Compare commits
16 Commits
test_unit
...
EditorUI_B
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90db50a241 | ||
|
|
b94ca96f67 | ||
|
|
dbc4ad9e23 | ||
|
|
3362351bce | ||
|
|
a5e80a7996 | ||
|
|
0d3d41abb6 | ||
|
|
9306d36936 | ||
|
|
c8fc878e9a | ||
|
|
e607ecc70c | ||
|
|
70fad68ccb | ||
|
|
18a882fac8 | ||
|
|
bb3d6764f1 | ||
|
|
d05bf21df3 | ||
|
|
e55cb831f2 | ||
|
|
700abcba2e | ||
|
|
cf894201dd |
35
mozilla/editor/Makefile.in
Normal file
35
mozilla/editor/Makefile.in
Normal file
@@ -0,0 +1,35 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public idl
|
||||
|
||||
ifdef MOZ_EDITOR
|
||||
DIRS += base ui
|
||||
endif
|
||||
|
||||
DIRS += txmgr txtsvc
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
130
mozilla/editor/base/ChangeAttributeTxn.cpp
Normal file
130
mozilla/editor/base/ChangeAttributeTxn.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
ChangeAttributeTxn::ChangeAttributeTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
ChangeAttributeTxn::~ChangeAttributeTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
||||
nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue,
|
||||
PRBool aRemoveAttribute)
|
||||
{
|
||||
if (nsnull!=aEditor && nsnull!=aElement)
|
||||
{
|
||||
mEditor = aEditor;
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mAttribute = aAttribute;
|
||||
mValue = aValue;
|
||||
mRemoveAttribute = aRemoveAttribute;
|
||||
mAttributeWasSet=PR_FALSE;
|
||||
mUndoValue="";
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Do(void)
|
||||
{
|
||||
// need to get the current value of the attribute and save it, and set mAttributeWasSet
|
||||
nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, mAttributeWasSet);
|
||||
// XXX: hack until attribute-was-set code is implemented
|
||||
if (PR_FALSE==mUndoValue.Equals(""))
|
||||
mAttributeWasSet=PR_TRUE;
|
||||
// XXX: end hack
|
||||
|
||||
// now set the attribute to the new value
|
||||
if (PR_FALSE==mRemoveAttribute)
|
||||
result = mElement->SetAttribute(mAttribute, mValue);
|
||||
else
|
||||
result = mElement->RemoveAttribute(mAttribute);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Undo(void)
|
||||
{
|
||||
nsresult result=NS_OK;
|
||||
if (PR_TRUE==mAttributeWasSet)
|
||||
result = mElement->SetAttribute(mAttribute, mUndoValue);
|
||||
else
|
||||
result = mElement->RemoveAttribute(mAttribute);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Redo(void)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
if (PR_FALSE==mRemoveAttribute)
|
||||
result = mElement->SetAttribute(mAttribute, mValue);
|
||||
else
|
||||
result = mElement->RemoveAttribute(mAttribute);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
if (PR_FALSE==mRemoveAttribute)
|
||||
*aString="Change Attribute: ";
|
||||
else
|
||||
*aString="Remove Attribute: ";
|
||||
*aString += mAttribute;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeAttributeTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
if (PR_FALSE==mRemoveAttribute)
|
||||
*aString="Change Attribute: ";
|
||||
else
|
||||
*aString="Add Attribute: ";
|
||||
*aString += mAttribute;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
102
mozilla/editor/base/ChangeAttributeTxn.h
Normal file
102
mozilla/editor/base/ChangeAttributeTxn.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef ChangeAttributeTxn_h__
|
||||
#define ChangeAttributeTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIEditor.h"
|
||||
|
||||
#define CHANGE_ATTRIBUTE_TXN_CID \
|
||||
{/* 97818860-ac48-11d2-86d8-000064657374 */ \
|
||||
0x97818860, 0xac48, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that changes an attribute of a content node.
|
||||
* This transaction covers add, remove, and change attribute.
|
||||
*/
|
||||
class ChangeAttributeTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = CHANGE_ATTRIBUTE_TXN_CID; return iid; }
|
||||
|
||||
virtual ~ChangeAttributeTxn();
|
||||
|
||||
/** Initialize the transaction.
|
||||
* @param aEditor the object providing core editing operations
|
||||
* @param aNode the node whose attribute will be changed
|
||||
* @param aAttribute the name of the attribute to change
|
||||
* @param aValue the new value for aAttribute, if aRemoveAttribute is false
|
||||
* @param aRemoveAttribute if PR_TRUE, remove aAttribute from aNode
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
nsIDOMElement *aNode,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue,
|
||||
PRBool aRemoveAttribute);
|
||||
|
||||
private:
|
||||
ChangeAttributeTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the editor that created this transaction */
|
||||
nsIEditor* mEditor;
|
||||
|
||||
/** the element to operate upon */
|
||||
nsCOMPtr<nsIDOMElement> mElement;
|
||||
|
||||
/** the attribute to change */
|
||||
nsString mAttribute;
|
||||
|
||||
/** the value to set the attribute to (ignored if mRemoveAttribute==PR_TRUE) */
|
||||
nsString mValue;
|
||||
|
||||
/** the value to set the attribute to for undo */
|
||||
nsString mUndoValue;
|
||||
|
||||
/** PR_TRUE if the mAttribute was set on mElement at the time of execution */
|
||||
PRBool mAttributeWasSet;
|
||||
|
||||
/** PR_TRUE if the operation is to remove mAttribute from mElement */
|
||||
PRBool mRemoveAttribute;
|
||||
|
||||
friend class TransactionFactory;
|
||||
};
|
||||
|
||||
#endif
|
||||
236
mozilla/editor/base/CreateElementTxn.cpp
Normal file
236
mozilla/editor/base/CreateElementTxn.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "CreateElementTxn.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
CreateElementTxn::CreateElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Init(nsIEditor *aEditor,
|
||||
const nsString &aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent)
|
||||
{
|
||||
NS_ASSERTION(aEditor&&aParent, "null args");
|
||||
if (aEditor && aParent)
|
||||
{
|
||||
mEditor = aEditor;
|
||||
mTag = aTag;
|
||||
mParent = do_QueryInterface(aParent);
|
||||
mOffsetInParent = aOffsetInParent;
|
||||
#ifdef NS_DEBUG
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> testChildNodes;
|
||||
nsresult testResult = mParent->GetChildNodes(getter_AddRefs(testChildNodes));
|
||||
NS_ASSERTION(testChildNodes, "bad parent type, can't have children.");
|
||||
NS_ASSERTION(NS_SUCCEEDED(testResult), "bad result.");
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
|
||||
CreateElementTxn::~CreateElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("Do Create Element parent = %p, offset = %d\n",
|
||||
mParent.get(), mOffsetInParent); }
|
||||
NS_ASSERTION(mEditor, "bad state -- null editor");
|
||||
nsresult result = NS_ERROR_NULL_POINTER;
|
||||
if (mEditor)
|
||||
{
|
||||
// create a new node
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
result = mEditor->GetDocument(getter_AddRefs(doc));
|
||||
if ((NS_SUCCEEDED(result)) && (doc))
|
||||
{
|
||||
if (nsEditor::GetTextNodeTag() == mTag)
|
||||
{
|
||||
const nsString stringData;
|
||||
nsCOMPtr<nsIDOMText>newTextNode;
|
||||
result = doc->CreateTextNode(stringData, getter_AddRefs(newTextNode));
|
||||
if (NS_SUCCEEDED(result) && newTextNode) {
|
||||
mNewNode = do_QueryInterface(newTextNode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
result = doc->CreateElement(mTag, getter_AddRefs(newElement));
|
||||
if (NS_SUCCEEDED(result) && newElement) {
|
||||
mNewNode = do_QueryInterface(newElement);
|
||||
}
|
||||
}
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewNode)), "could not create element.");
|
||||
if ((NS_SUCCEEDED(result)) && (mNewNode))
|
||||
{
|
||||
if (gNoisy) { printf(" newNode = %p\n", mNewNode.get()); }
|
||||
// insert the new node
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
if (CreateElementTxn::eAppend==(PRInt32)mOffsetInParent)
|
||||
{
|
||||
result = mParent->AppendChild(mNewNode, getter_AddRefs(resultNode));
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
result = mParent->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if ((NS_SUCCEEDED(result)) && (childNodes))
|
||||
{
|
||||
PRUint32 count;
|
||||
childNodes->GetLength(&count);
|
||||
if (mOffsetInParent>count)
|
||||
mOffsetInParent = count;
|
||||
result = childNodes->Item(mOffsetInParent, getter_AddRefs(mRefNode));
|
||||
if (NS_SUCCEEDED(result)) // note, it's ok for mRefNode to be null. that means append
|
||||
{
|
||||
result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
PRInt32 offset=0;
|
||||
nsEditor::GetChildOffset(mNewNode, mParent, offset);
|
||||
selectionResult = selection->Collapse(mParent, offset+1);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after insert.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Undo Create Element, mParent = %p, node = %p\n",
|
||||
mParent.get(), mNewNode.get()); }
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->RemoveChild(mNewNode, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
PRInt32 offset=0;
|
||||
if (mRefNode) {
|
||||
nsEditor::GetChildOffset(mRefNode, mParent, offset);
|
||||
}
|
||||
selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Redo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Redo Create Element\n"); }
|
||||
|
||||
// first, reset mNewNode so it has no attributes or content
|
||||
nsCOMPtr<nsIDOMCharacterData>nodeAsText;
|
||||
nodeAsText = do_QueryInterface(mNewNode);
|
||||
if (nodeAsText)
|
||||
{
|
||||
nsAutoString nullString;
|
||||
nodeAsText->SetData(nullString);
|
||||
}
|
||||
|
||||
// now, reinsert mNewNode
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
PRInt32 offset=0;
|
||||
nsEditor::GetChildOffset(mNewNode, mParent, offset);
|
||||
nsresult selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Element: ";
|
||||
*aString += mTag;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Create Element: ";
|
||||
*aString += mTag;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::GetNewNode(nsIDOMNode **aNewNode)
|
||||
{
|
||||
if (!aNewNode)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!mNewNode)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
*aNewNode = mNewNode;
|
||||
NS_ADDREF(*aNewNode);
|
||||
return NS_OK;
|
||||
}
|
||||
102
mozilla/editor/base/CreateElementTxn.h
Normal file
102
mozilla/editor/base/CreateElementTxn.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef CreateElementTxn_h__
|
||||
#define CreateElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define CREATE_ELEMENT_TXN_CID \
|
||||
{/* 7a6393c0-ac48-11d2-86d8-000064657374 */ \
|
||||
0x7a6393c0, 0xac48, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that creates a new node in the content tree.
|
||||
*/
|
||||
class CreateElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = CREATE_ELEMENT_TXN_CID; return iid; }
|
||||
|
||||
enum { eAppend=-1 };
|
||||
|
||||
/** Initialize the transaction.
|
||||
* @param aEditor the provider of basic editing functionality
|
||||
* @param aTag the tag (P, HR, TABLE, etc.) for the new element
|
||||
* @param aParent the node into which the new element will be inserted
|
||||
* @param aOffsetInParent the location in aParent to insert the new element
|
||||
* if eAppend, the new element is appended as the last child
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRUint32 aOffsetInParent);
|
||||
|
||||
private:
|
||||
CreateElementTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~CreateElementTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
|
||||
|
||||
protected:
|
||||
|
||||
/** the document into which the new node will be inserted */
|
||||
nsIEditor* mEditor;
|
||||
|
||||
/** the tag (mapping to object type) for the new element */
|
||||
nsString mTag;
|
||||
|
||||
/** the node into which the new node will be inserted */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
|
||||
/** the index in mParent for the new node */
|
||||
PRUint32 mOffsetInParent;
|
||||
|
||||
/** the new node to insert */
|
||||
nsCOMPtr<nsIDOMNode> mNewNode;
|
||||
|
||||
/** the node we will insert mNewNode before. We compute this ourselves. */
|
||||
nsCOMPtr<nsIDOMNode> mRefNode;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
174
mozilla/editor/base/DeleteElementTxn.cpp
Normal file
174
mozilla/editor/base/DeleteElementTxn.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "DeleteElementTxn.h"
|
||||
#ifdef NS_DEBUG
|
||||
#include "nsIDOMElement.h"
|
||||
#endif
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
|
||||
DeleteElementTxn::DeleteElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Init(nsIDOMNode *aElement)
|
||||
{
|
||||
if (nsnull!=aElement) {
|
||||
mElement = do_QueryInterface(aElement);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DeleteElementTxn::~DeleteElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Do Delete Element element = %p\n", this, mElement.get()); }
|
||||
if (!mElement)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result = mElement->GetParentNode(getter_AddRefs(mParent));
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
if (!mParent) {
|
||||
return NS_OK; // this is a no-op, there's no parent to delete mElement from
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// begin debug output
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
element = do_QueryInterface(mElement);
|
||||
nsAutoString elementTag="text node";
|
||||
if (element)
|
||||
element->GetTagName(elementTag);
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
parentElement = do_QueryInterface(mParent);
|
||||
nsAutoString parentElementTag="text node";
|
||||
if (parentElement)
|
||||
parentElement->GetTagName(parentElementTag);
|
||||
char *c, *p;
|
||||
c = elementTag.ToNewCString();
|
||||
p = parentElementTag.ToNewCString();
|
||||
if (c&&p)
|
||||
{
|
||||
if (gNoisy)
|
||||
printf(" DeleteElementTxn: deleting child %s from parent %s\n", c, p);
|
||||
delete [] c;
|
||||
delete [] p;
|
||||
}
|
||||
// end debug output
|
||||
#endif
|
||||
|
||||
// remember which child mElement was (by remembering which child was next)
|
||||
result = mElement->GetNextSibling(getter_AddRefs(mRefNode)); // can return null mRefNode
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Undo Delete Element element = %p, parent = %p\n", this, mElement.get(), mParent.get()); }
|
||||
if (!mParent) { return NS_OK; } // this is a legal state, the txn is a no-op
|
||||
if (!mElement) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// begin debug output
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
element = do_QueryInterface(mElement);
|
||||
nsAutoString elementTag="text node";
|
||||
if (element)
|
||||
element->GetTagName(elementTag);
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
parentElement = do_QueryInterface(mParent);
|
||||
nsAutoString parentElementTag="text node";
|
||||
if (parentElement)
|
||||
parentElement->GetTagName(parentElementTag);
|
||||
char *c, *p;
|
||||
c = elementTag.ToNewCString();
|
||||
p = parentElementTag.ToNewCString();
|
||||
if (c&&p)
|
||||
{
|
||||
if (gNoisy)
|
||||
printf(" DeleteElementTxn: inserting child %s back into parent %s\n", c, p);
|
||||
delete [] c;
|
||||
delete [] p;
|
||||
}
|
||||
// end debug output
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->InsertBefore(mElement, mRefNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Redo(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Redo Delete Element element = %p, parent = %p\n", this, mElement.get(), mParent.get()); }
|
||||
if (!mParent) { return NS_OK; } // this is a legal state, the txn is a no-op
|
||||
if (!mElement) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Element: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Element: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
84
mozilla/editor/base/DeleteElementTxn.h
Normal file
84
mozilla/editor/base/DeleteElementTxn.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef DeleteElementTxn_h__
|
||||
#define DeleteElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define DELETE_ELEMENT_TXN_CID \
|
||||
{/* 6fd77770-ac49-11d2-86d8-000064657374 */ \
|
||||
0x6fd77770, 0xac49, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that deletes a single element
|
||||
*/
|
||||
class DeleteElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = DELETE_ELEMENT_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aElement the node to delete
|
||||
*/
|
||||
NS_IMETHOD Init(nsIDOMNode *aElement);
|
||||
|
||||
private:
|
||||
DeleteElementTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~DeleteElementTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the element to delete */
|
||||
nsCOMPtr<nsIDOMNode> mElement;
|
||||
|
||||
/** the node into which the new node will be inserted */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
|
||||
/** the index in mParent for the new node */
|
||||
PRUint32 mOffsetInParent;
|
||||
|
||||
/** the node we will insert mNewNode before. We compute this ourselves. */
|
||||
nsCOMPtr<nsIDOMNode> mRefNode;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
363
mozilla/editor/base/DeleteRangeTxn.cpp
Normal file
363
mozilla/editor/base/DeleteRangeTxn.cpp
Normal file
@@ -0,0 +1,363 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "DeleteRangeTxn.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "DeleteElementTxn.h"
|
||||
#include "TransactionFactory.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsLayoutCID.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
#include "nsIDOMElement.h"
|
||||
#endif
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
DeleteRangeTxn::DeleteRangeTxn()
|
||||
: EditAggregateTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange)
|
||||
{
|
||||
if (aEditor && aRange)
|
||||
{
|
||||
mEditor = aEditor;
|
||||
mRange = do_QueryInterface(aRange);
|
||||
|
||||
nsresult result = aRange->GetStartParent(getter_AddRefs(mStartParent));
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "GetStartParent failed.");
|
||||
result = aRange->GetEndParent(getter_AddRefs(mEndParent));
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "GetEndParent failed.");
|
||||
result = aRange->GetStartOffset(&mStartOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "GetStartOffset failed.");
|
||||
result = aRange->GetEndOffset(&mEndOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "GetEndOffset failed.");
|
||||
result = aRange->GetCommonParent(getter_AddRefs(mCommonParent));
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "GetCommonParent failed.");
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
{
|
||||
PRUint32 count;
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode;
|
||||
textNode = do_QueryInterface(mStartParent);
|
||||
if (textNode)
|
||||
textNode->GetLength(&count);
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> children;
|
||||
result = mStartParent->GetChildNodes(getter_AddRefs(children));
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad start child list");
|
||||
children->GetLength(&count);
|
||||
}
|
||||
NS_ASSERTION(mStartOffset<=(PRInt32)count, "bad start offset");
|
||||
|
||||
textNode = do_QueryInterface(mEndParent);
|
||||
if (textNode)
|
||||
textNode->GetLength(&count);
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> children;
|
||||
result = mEndParent->GetChildNodes(getter_AddRefs(children));
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list");
|
||||
children->GetLength(&count);
|
||||
}
|
||||
NS_ASSERTION(mEndOffset<=(PRInt32)count, "bad end offset");
|
||||
if (gNoisy)
|
||||
{
|
||||
printf ("DeleteRange: %d of %p to %d of %p\n",
|
||||
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
DeleteRangeTxn::~DeleteRangeTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("Do Delete Range\n"); }
|
||||
if (!mStartParent || !mEndParent || !mCommonParent)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
|
||||
// build the child transactions
|
||||
|
||||
if (mStartParent==mEndParent)
|
||||
{ // the selection begins and ends in the same node
|
||||
result = CreateTxnsToDeleteBetween(mStartParent, mStartOffset, mEndOffset);
|
||||
}
|
||||
else
|
||||
{ // the selection ends in a different node from where it started
|
||||
// delete the relevant content in the start node
|
||||
result = CreateTxnsToDeleteContent(mStartParent, mStartOffset, nsIEditor::eDeleteNext);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
// delete the intervening nodes
|
||||
result = CreateTxnsToDeleteNodesBetween();
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
// delete the relevant content in the end node
|
||||
result = CreateTxnsToDeleteContent(mEndParent, mEndOffset, nsIEditor::eDeletePrevious);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we've successfully built this aggregate transaction, then do it.
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = EditAggregateTxn::Do();
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// set the resulting selection
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mStartParent, mStartOffset);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Undo Delete Range\n"); }
|
||||
if (!mStartParent || !mEndParent || !mCommonParent)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result = EditAggregateTxn::Undo();
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// set the resulting selection
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
selection->Collapse(mStartParent, mStartOffset);
|
||||
selection->Extend(mEndParent, mEndOffset);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Redo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Redo Delete Range\n"); }
|
||||
if (!mStartParent || !mEndParent || !mCommonParent)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result = EditAggregateTxn::Redo();
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// set the resulting selection
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mStartParent, mStartOffset);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Range: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Range: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent,
|
||||
PRUint32 aStartOffset,
|
||||
PRUint32 aEndOffset)
|
||||
{
|
||||
nsresult result;
|
||||
// see what kind of node we have
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode;
|
||||
textNode = do_QueryInterface(aStartParent);
|
||||
if (textNode)
|
||||
{ // if the node is a text node, then delete text content
|
||||
DeleteTextTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(DeleteTextTxn::GetCID(), (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
PRInt32 numToDel;
|
||||
if (aStartOffset==aEndOffset)
|
||||
numToDel = 1;
|
||||
else
|
||||
numToDel = aEndOffset-aStartOffset;
|
||||
txn->Init(mEditor, textNode, aStartOffset, numToDel);
|
||||
AppendChild(txn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRUint32 childCount;
|
||||
nsCOMPtr<nsIDOMNodeList> children;
|
||||
result = aStartParent->GetChildNodes(getter_AddRefs(children));
|
||||
if ((NS_SUCCEEDED(result)) && children)
|
||||
{
|
||||
children->GetLength(&childCount);
|
||||
NS_ASSERTION(aEndOffset<=childCount, "bad aEndOffset");
|
||||
PRUint32 i;
|
||||
for (i=aStartOffset; i<=aEndOffset; i++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
result = children->Item(i, getter_AddRefs(child));
|
||||
if ((NS_SUCCEEDED(result)) && child)
|
||||
{
|
||||
DeleteElementTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(DeleteElementTxn::GetCID(), (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
txn->Init(child);
|
||||
AppendChild(txn);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteContent(nsIDOMNode *aParent,
|
||||
PRUint32 aOffset,
|
||||
nsIEditor::ESelectionCollapseDirection aAction)
|
||||
{
|
||||
nsresult result;
|
||||
// see what kind of node we have
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode;
|
||||
textNode = do_QueryInterface(aParent);
|
||||
if (textNode)
|
||||
{ // if the node is a text node, then delete text content
|
||||
PRUint32 start, numToDelete;
|
||||
if (nsIEditor::eDeleteNext == aAction)
|
||||
{
|
||||
start=aOffset;
|
||||
textNode->GetLength(&numToDelete);
|
||||
numToDelete -= aOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=0;
|
||||
numToDelete=aOffset;
|
||||
}
|
||||
|
||||
if (numToDelete)
|
||||
{
|
||||
DeleteTextTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(DeleteTextTxn::GetCID(), (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
txn->Init(mEditor, textNode, start, numToDelete);
|
||||
AppendChild(txn);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteNodesBetween()
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
nsCOMPtr<nsIContentIterator> iter;
|
||||
|
||||
result = nsComponentManager::CreateInstance(kSubtreeIteratorCID,
|
||||
nsnull,
|
||||
nsIContentIterator::GetIID(),
|
||||
getter_AddRefs(iter));
|
||||
if (!NS_SUCCEEDED(result))
|
||||
return result;
|
||||
result = iter->Init(mRange);
|
||||
if (!NS_SUCCEEDED(result))
|
||||
return result;
|
||||
|
||||
while (NS_COMFALSE == iter->IsDone())
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIContent> content;
|
||||
result = iter->CurrentNode(getter_AddRefs(content));
|
||||
node = do_QueryInterface(content);
|
||||
if ((NS_SUCCEEDED(result)) && node)
|
||||
{
|
||||
DeleteElementTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(DeleteElementTxn::GetCID(), (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
txn->Init(node);
|
||||
AppendChild(txn);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
iter->Next();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
113
mozilla/editor/base/DeleteRangeTxn.h
Normal file
113
mozilla/editor/base/DeleteRangeTxn.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef DeleteRangeTxn_h__
|
||||
#define DeleteRangeTxn_h__
|
||||
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIDOMDocument;
|
||||
|
||||
#define DELETE_RANGE_TXN_CID \
|
||||
{/* 5ec6b260-ac49-11d2-86d8-000064657374 */ \
|
||||
0x5ec6b260, 0xac49, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
class nsIDOMRange;
|
||||
class nsIEditor;
|
||||
|
||||
/**
|
||||
* A transaction that deletes an entire range in the content tree
|
||||
*/
|
||||
class DeleteRangeTxn : public EditAggregateTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = DELETE_RANGE_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aEditor the object providing basic editing operations
|
||||
* @param aRange the range to delete
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor, nsIDOMRange *aRange);
|
||||
|
||||
private:
|
||||
DeleteRangeTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~DeleteRangeTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent,
|
||||
PRUint32 aStartOffset,
|
||||
PRUint32 aEndOffset);
|
||||
|
||||
NS_IMETHOD CreateTxnsToDeleteNodesBetween();
|
||||
|
||||
NS_IMETHOD CreateTxnsToDeleteContent(nsIDOMNode *aParent,
|
||||
PRUint32 aOffset,
|
||||
nsIEditor::ESelectionCollapseDirection aAction);
|
||||
|
||||
protected:
|
||||
|
||||
/** p1 in the range */
|
||||
nsCOMPtr<nsIDOMRange> mRange; // is this really an owning ptr?
|
||||
|
||||
/** p1 in the range */
|
||||
nsCOMPtr<nsIDOMNode> mStartParent;
|
||||
|
||||
/** p1 offset */
|
||||
PRInt32 mStartOffset;
|
||||
|
||||
/** p2 in the range */
|
||||
nsCOMPtr<nsIDOMNode> mEndParent;
|
||||
|
||||
/** the closest common parent of p1 and p2 */
|
||||
nsCOMPtr<nsIDOMNode> mCommonParent;
|
||||
|
||||
/** p2 offset */
|
||||
PRInt32 mEndOffset;
|
||||
|
||||
/** the editor for this transaction */
|
||||
nsIEditor* mEditor;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
132
mozilla/editor/base/DeleteTextTxn.cpp
Normal file
132
mozilla/editor/base/DeleteTextTxn.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
DeleteTextTxn::DeleteTextTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
DeleteTextTxn::~DeleteTextTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aNumCharsToDelete)
|
||||
{
|
||||
NS_ASSERTION(aEditor&&aElement, "bad arg");
|
||||
mEditor = aEditor;
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mOffset = aOffset;
|
||||
mNumCharsToDelete = aNumCharsToDelete;
|
||||
NS_ASSERTION(0!=aNumCharsToDelete, "bad arg, numCharsToDelete");
|
||||
PRUint32 count;
|
||||
aElement->GetLength(&count);
|
||||
NS_ASSERTION(count>=aNumCharsToDelete, "bad arg, numCharsToDelete. Not enough characters in node");
|
||||
NS_ASSERTION(count>=aOffset+aNumCharsToDelete, "bad arg, numCharsToDelete. Not enough characters in node");
|
||||
mDeletedText = "";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("Do Delete Text\n"); }
|
||||
nsresult result = NS_ERROR_NULL_POINTER;
|
||||
if (mEditor && mElement)
|
||||
{
|
||||
// get the text that we're about to delete
|
||||
result = mElement->SubstringData(mOffset, mNumCharsToDelete, mDeletedText);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "could not get text to delete.");
|
||||
result = mElement->DeleteData(mOffset, mNumCharsToDelete);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//XXX: we may want to store the selection state and restore it properly
|
||||
// was it an insertion point or an extended selection?
|
||||
NS_IMETHODIMP DeleteTextTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Undo Delete Text\n"); }
|
||||
nsresult result = NS_ERROR_NULL_POINTER;
|
||||
if (mEditor && mElement)
|
||||
{
|
||||
result = mElement->InsertData(mOffset, mDeletedText);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Text: ";
|
||||
*aString += mDeletedText;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteTextTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Text: ";
|
||||
*aString += mDeletedText;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
91
mozilla/editor/base/DeleteTextTxn.h
Normal file
91
mozilla/editor/base/DeleteTextTxn.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef DeleteTextTxn_h__
|
||||
#define DeleteTextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define DELETE_TEXT_TXN_CID \
|
||||
{/* 4d3a2720-ac49-11d2-86d8-000064657374 */ \
|
||||
0x4d3a2720, 0xac49, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that removes text from a content node.
|
||||
*/
|
||||
class DeleteTextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = DELETE_TEXT_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aEditor the provider of basic editing operations
|
||||
* @param aElement the content node to remove text from
|
||||
* @param aOffset the location in aElement to begin the deletion
|
||||
* @param aNumCharsToDelete the number of characters to delete. Not the number of bytes!
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aNumCharsToDelete);
|
||||
|
||||
private:
|
||||
DeleteTextTxn();
|
||||
|
||||
public:
|
||||
virtual ~DeleteTextTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the provider of basic editing operations */
|
||||
nsIEditor* mEditor;
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsCOMPtr<nsIDOMCharacterData> mElement;
|
||||
|
||||
/** the offset into mElement where the deletion is to take place */
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the number of characters to delete */
|
||||
PRUint32 mNumCharsToDelete;
|
||||
|
||||
/** the text that was deleted */
|
||||
nsString mDeletedText;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
236
mozilla/editor/base/EditAggregateTxn.cpp
Normal file
236
mozilla/editor/base/EditAggregateTxn.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL") you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
EditAggregateTxn::EditAggregateTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
// base class does this: NS_INIT_REFCNT();
|
||||
mChildren = new nsVoidArray();
|
||||
}
|
||||
|
||||
EditAggregateTxn::~EditAggregateTxn()
|
||||
{
|
||||
if (nsnull!=mChildren)
|
||||
{
|
||||
PRInt32 i;
|
||||
PRInt32 count = mChildren->Count();
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
||||
NS_IF_RELEASE(txn);
|
||||
}
|
||||
delete mChildren;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::Do(void)
|
||||
{
|
||||
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
||||
if (nsnull!=mChildren)
|
||||
{
|
||||
PRInt32 i;
|
||||
PRInt32 count = mChildren->Count();
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
||||
result = txn->Do();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::Undo(void)
|
||||
{
|
||||
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
||||
if (nsnull!=mChildren)
|
||||
{
|
||||
PRInt32 i;
|
||||
PRInt32 count = mChildren->Count();
|
||||
// undo goes through children backwards
|
||||
for (i=count-1; i>=0; i--)
|
||||
{
|
||||
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
||||
result = txn->Undo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::Redo(void)
|
||||
{
|
||||
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
||||
if (nsnull!=mChildren)
|
||||
{
|
||||
PRInt32 i;
|
||||
PRInt32 count = mChildren->Count();
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
||||
result = txn->Redo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
if (nsnull!=mChildren)
|
||||
{
|
||||
PRInt32 count = mChildren->Count();
|
||||
NS_ASSERTION(count>0, "bad count");
|
||||
if (0<count)
|
||||
{
|
||||
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(count-1));
|
||||
result = txn->Merge(aDidMerge, aTransaction);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::AppendChild(EditTxn *aTxn)
|
||||
{
|
||||
if ((nsnull!=mChildren) && (nsnull!=aTxn))
|
||||
{
|
||||
mChildren->AppendElement(aTxn);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetCount(PRInt32 *aCount)
|
||||
{
|
||||
if (!aCount) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aCount=0;
|
||||
if (mChildren) {
|
||||
*aCount = mChildren->Count();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetTxnAt(PRInt32 aIndex, EditTxn **aTxn)
|
||||
{
|
||||
if (!aTxn) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (!mChildren) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
const PRInt32 txnCount = mChildren->Count();
|
||||
if (0>aIndex || txnCount<=aIndex) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
*aTxn = (EditTxn *)(mChildren->ElementAt(aIndex));
|
||||
if (!*aTxn)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
NS_ADDREF(*aTxn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::SetName(nsIAtom *aName)
|
||||
{
|
||||
mName = do_QueryInterface(aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
|
||||
{
|
||||
if (aName)
|
||||
{
|
||||
if (mName)
|
||||
{
|
||||
*aName = mName;
|
||||
NS_ADDREF(*aName);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) EditAggregateTxn::AddRef(void)
|
||||
{
|
||||
return EditTxn::AddRef();
|
||||
}
|
||||
|
||||
//NS_IMPL_RELEASE_INHERITED(Class, Super)
|
||||
NS_IMETHODIMP_(nsrefcnt) EditAggregateTxn::Release(void)
|
||||
{
|
||||
return EditTxn::Release();
|
||||
}
|
||||
|
||||
//NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface)
|
||||
NS_IMETHODIMP EditAggregateTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(EditAggregateTxn::GetCID())) {
|
||||
*aInstancePtr = (nsISupports*)(EditAggregateTxn*)(this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return EditTxn::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
91
mozilla/editor/base/EditAggregateTxn.h
Normal file
91
mozilla/editor/base/EditAggregateTxn.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef EditAggregateTxn_h__
|
||||
#define EditAggregateTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define EDIT_AGGREGATE_TXN_CID \
|
||||
{/* 345921a0-ac49-11d2-86d8-000064657374 */ \
|
||||
0x345921a0, 0xac49, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
class nsVoidArray;
|
||||
|
||||
/**
|
||||
* base class for all document editing transactions that require aggregation.
|
||||
* provides a list of child transactions.
|
||||
*/
|
||||
class EditAggregateTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
static const nsIID& GetCID() { static nsIID cid = EDIT_AGGREGATE_TXN_CID; return cid; }
|
||||
|
||||
EditAggregateTxn();
|
||||
|
||||
virtual ~EditAggregateTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
/** append a transaction to this aggregate */
|
||||
NS_IMETHOD AppendChild(EditTxn *aTxn);
|
||||
|
||||
/** get the number of nested txns.
|
||||
* This is the number of top-level txns, it does not do recursive decent.
|
||||
*/
|
||||
NS_IMETHOD GetCount(PRInt32 *aCount);
|
||||
|
||||
/** get the txn at index aIndex.
|
||||
* returns NS_ERROR_UNEXPECTED if there is no txn at aIndex.
|
||||
*/
|
||||
NS_IMETHOD GetTxnAt(PRInt32 aIndex, EditTxn **aTxn);
|
||||
|
||||
/** set the name assigned to this txn */
|
||||
NS_IMETHOD SetName(nsIAtom *aName);
|
||||
|
||||
/** get the name assigned to this txn */
|
||||
NS_IMETHOD GetName(nsIAtom **aName);
|
||||
|
||||
protected:
|
||||
|
||||
//XXX: if this was an nsISupportsArray, it would handle refcounting for us
|
||||
nsVoidArray * mChildren;
|
||||
nsCOMPtr<nsIAtom> mName;
|
||||
};
|
||||
|
||||
#endif
|
||||
404
mozilla/editor/base/EditTable.cpp
Normal file
404
mozilla/editor/base/EditTable.cpp
Normal file
@@ -0,0 +1,404 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMAttr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIDOMHTMLTableElement.h"
|
||||
#include "nsIDOMHTMLTableCellElement.h"
|
||||
#include "nsITableCellLayout.h" // For efficient access to table cell
|
||||
#include "nsITableLayout.h" // data owned by the table and cell frames
|
||||
|
||||
// transactions the editor knows how to build
|
||||
//#include "TransactionFactory.h"
|
||||
//#include "EditAggregateTxn.h"
|
||||
//#include "nsIDOMHTMLCollection.h"
|
||||
#include "nsHTMLEditor.h"
|
||||
|
||||
// Table Editing methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertTable()
|
||||
{
|
||||
nsresult res=NS_ERROR_NOT_INITIALIZED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
nsCOMPtr<nsIDOMNode> cellParent;
|
||||
PRInt32 cellOffset, startRow, startCol;
|
||||
nsresult res = GetCellContext(selection, table, cell, cellParent, cellOffset, startRow, startCol);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
PRInt32 i;
|
||||
for (i = 0; i < aNumber; i++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> newCell;
|
||||
res = CreateElementWithDefaults("td", getter_AddRefs(newCell));
|
||||
if (NS_SUCCEEDED(res) && newCell)
|
||||
{
|
||||
if (aAfter) cellOffset++;
|
||||
res = InsertNode(newCell, cellParent, cellOffset);
|
||||
}
|
||||
}
|
||||
SetCaretAfterTableEdit(table, startRow, startCol, ePreviousColumn);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
nsCOMPtr<nsIDOMNode> cellParent;
|
||||
PRInt32 cellOffset, startRow, startCol;
|
||||
nsresult res = GetCellContext(selection, table, cell, cellParent, cellOffset, startRow, startCol);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
PRInt32 rowCount, colCount, row, col;
|
||||
if (NS_FAILED(GetTableSize(table, rowCount, colCount)))
|
||||
return NS_ERROR_FAILURE;
|
||||
for ( row = 0; row < rowCount; row++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> curCell;
|
||||
PRInt32 startRow, startCol, rowSpan, colSpan;
|
||||
PRBool isSelected;
|
||||
res = GetCellDataAt(table, row, col, *getter_AddRefs(curCell),
|
||||
startRow, startCol, rowSpan, colSpan, isSelected);
|
||||
if (NS_SUCCEEDED(res) && curCell)
|
||||
{
|
||||
//FINISH ME!
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
nsCOMPtr<nsIDOMNode> cellParent;
|
||||
PRInt32 cellOffset, startRow, startCol;
|
||||
nsresult res = GetCellContext(selection, table, cell, cellParent, cellOffset, startRow, startCol);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
selection->ClearSelection();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::DeleteTable()
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
nsCOMPtr<nsIDOMNode> cellParent;
|
||||
PRInt32 cellOffset, startRow, startCol;
|
||||
nsresult res = GetCellContext(selection, table, cell, cellParent, cellOffset, startRow, startCol);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
// Save where we need to restore the selection
|
||||
nsCOMPtr<nsIDOMNode> tableParent;
|
||||
PRInt32 tableOffset;
|
||||
if(NS_FAILED(table->GetParentNode(getter_AddRefs(tableParent))) || !tableParent)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
res = DeleteNode(table);
|
||||
|
||||
// Restore the selection (caret)
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
res = nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(res) || !selection)
|
||||
return res;
|
||||
selection->Collapse(tableParent, tableOffset);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::DeleteTableCell(PRInt32 aNumber)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
nsCOMPtr<nsIDOMNode> cellParent;
|
||||
PRInt32 cellOffset, startRow, startCol;
|
||||
nsresult res = GetCellContext(selection, table, cell, cellParent, cellOffset, startRow, startCol);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
selection->ClearSelection();
|
||||
PRInt32 i;
|
||||
for (i = 0; i < aNumber; i++)
|
||||
{
|
||||
//TODO: FINISH ME!
|
||||
if (NS_FAILED(DeleteNode(cell)))
|
||||
break;
|
||||
}
|
||||
SetCaretAfterTableEdit(table, startRow, startCol, ePreviousColumn);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::DeleteTableRow(PRInt32 aNumber)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::JoinTableCells(PRBool aCellToRight)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::NormalizeTable(nsIDOMElement *aTable)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex)
|
||||
{
|
||||
nsresult res=NS_ERROR_NOT_INITIALIZED;
|
||||
aColIndex=0; // initialize out params
|
||||
aRowIndex=0;
|
||||
if (!aCell)
|
||||
{
|
||||
// Get the selected cell or the cell enclosing the selection anchor
|
||||
nsCOMPtr<nsIDOMElement> cell;
|
||||
res = GetElementOrParentByTagName("td", nsnull, getter_AddRefs(cell));
|
||||
if (NS_SUCCEEDED(res) && cell)
|
||||
aCell = cell;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
res = NS_ERROR_FAILURE; // we return an error unless we get the index
|
||||
nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr
|
||||
|
||||
res = nsHTMLEditor::GetLayoutObject(aCell, &layoutObject);
|
||||
|
||||
if ((NS_SUCCEEDED(res)) && (nsnull!=layoutObject))
|
||||
{ // get the table cell interface from the frame
|
||||
nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted
|
||||
|
||||
res = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject));
|
||||
if ((NS_SUCCEEDED(res)) && (nsnull!=cellLayoutObject))
|
||||
{
|
||||
res = cellLayoutObject->GetCellIndexes(aRowIndex, aColIndex);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject)
|
||||
{
|
||||
*tableLayoutObject=nsnull;
|
||||
if (!aTable)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// frames are not ref counted, so don't use an nsCOMPtr
|
||||
nsISupports *layoutObject=nsnull;
|
||||
nsresult res = nsHTMLEditor::GetLayoutObject(aTable, &layoutObject);
|
||||
if ((NS_SUCCEEDED(res)) && (nsnull!=layoutObject))
|
||||
{ // get the table interface from the frame
|
||||
|
||||
res = layoutObject->QueryInterface(nsITableLayout::GetIID(),
|
||||
(void**)(tableLayoutObject));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Not scriptable: For convenience in C++ */
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& aColCount)
|
||||
{
|
||||
nsresult res=NS_ERROR_FAILURE;
|
||||
aRowCount = 0;
|
||||
aColCount = 0;
|
||||
if (!aTable)
|
||||
{
|
||||
// Get the selected talbe or the table enclosing the selection anchor
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
res = GetElementOrParentByTagName("table", nsnull, getter_AddRefs(table));
|
||||
if (NS_SUCCEEDED(res) && table)
|
||||
aTable = table;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// frames are not ref counted, so don't use an nsCOMPtr
|
||||
nsITableLayout *tableLayoutObject;
|
||||
res = GetTableLayoutObject(aTable, &tableLayoutObject);
|
||||
if ((NS_SUCCEEDED(res)) && (nsnull!=tableLayoutObject))
|
||||
{
|
||||
res = tableLayoutObject->GetTableSize(aRowCount, aColCount);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell,
|
||||
PRInt32& aStartRowIndex, PRInt32& aStartColIndex,
|
||||
PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected)
|
||||
{
|
||||
nsresult res=NS_ERROR_FAILURE;
|
||||
aCell = nsnull;
|
||||
aStartRowIndex = 0;
|
||||
aStartColIndex = 0;
|
||||
aRowSpan = 0;
|
||||
aColSpan = 0;
|
||||
aIsSelected = PR_FALSE;
|
||||
|
||||
if (!aTable)
|
||||
{
|
||||
// Get the selected talbe or the table enclosing the selection anchor
|
||||
nsCOMPtr<nsIDOMElement> table;
|
||||
res = GetElementOrParentByTagName("table", nsnull, getter_AddRefs(table));
|
||||
if (NS_SUCCEEDED(res) && table)
|
||||
aTable = table;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// frames are not ref counted, so don't use an nsCOMPtr
|
||||
nsITableLayout *tableLayoutObject;
|
||||
res = GetTableLayoutObject(aTable, &tableLayoutObject);
|
||||
if ((NS_SUCCEEDED(res)) && (nsnull!=tableLayoutObject))
|
||||
{
|
||||
// Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND when
|
||||
// the index(es) are out of bounds
|
||||
res = tableLayoutObject->GetCellDataAt(aRowIndex, aColIndex, aCell,
|
||||
aStartRowIndex, aStartColIndex,
|
||||
aRowSpan, aColSpan, aIsSelected);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// When all you want is the cell
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell)
|
||||
{
|
||||
PRInt32 aStartRowIndex, aStartColIndex, aRowSpan, aColSpan;
|
||||
PRBool aIsSelected;
|
||||
return GetCellDataAt(aTable, aRowIndex, aColIndex, aCell,
|
||||
aStartRowIndex, aStartColIndex, aRowSpan, aColSpan, aIsSelected);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetCellContext(nsCOMPtr<nsIDOMSelection> &aSelection,
|
||||
nsCOMPtr<nsIDOMElement> &aTable, nsCOMPtr<nsIDOMElement> &aCell,
|
||||
nsCOMPtr<nsIDOMNode> &aCellParent, PRInt32& aCellOffset,
|
||||
PRInt32& aRow, PRInt32& aCol)
|
||||
{
|
||||
nsresult res = nsEditor::GetSelection(getter_AddRefs(aSelection));
|
||||
if (NS_FAILED(res) || !aSelection)
|
||||
return res;
|
||||
|
||||
// TODO: Should we look for the "first" cell instead?
|
||||
// Messy! We would need to iterate through the selection to find the first enclosing cell
|
||||
nsCOMPtr<nsIDOMNode> anchorNode;
|
||||
if(NS_FAILED(aSelection->GetAnchorNode(getter_AddRefs(anchorNode))) || !anchorNode)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Test if anchor is a cell node (should I bother to check header as well?
|
||||
nsCOMPtr<nsIDOMHTMLTableCellElement> cellElement = do_QueryInterface(anchorNode);
|
||||
if (cellElement)
|
||||
{
|
||||
aCell = do_QueryInterface(anchorNode);
|
||||
} else {
|
||||
// Get the anchor's first child, in case the selection is composed of cells
|
||||
PRInt32 offset;
|
||||
if (NS_FAILED(aSelection->GetAnchorOffset(&offset)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> anchorChild = GetChildAt(anchorNode, offset);
|
||||
if(!anchorChild)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the cell enclosing the selection anchor
|
||||
if(NS_FAILED(GetElementOrParentByTagName("td", anchorChild, getter_AddRefs(aCell))) || !aCell)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if(NS_FAILED(GetElementOrParentByTagName("table", aCell, getter_AddRefs(aTable))) || !aTable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(NS_FAILED(aCell->GetParentNode(getter_AddRefs(aCellParent))) || !aCellParent)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get current cell location so we can put caret back there when done
|
||||
res = GetCellIndexes(aCell, aRow, aCol);
|
||||
if(NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
return GetChildOffset(aCell, aCellParent, aCellOffset);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::SetCaretAfterTableEdit(nsIDOMElement* aTable, PRInt32 aCol, PRInt32 aRow, SetCaretSearchDirection aDirection)
|
||||
{
|
||||
nsresult res = NS_ERROR_NOT_INITIALIZED;
|
||||
if (!aTable)
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
res = nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
if (!NS_SUCCEEDED(res) || !selection)
|
||||
{
|
||||
#ifdef DEBUG_cmanske
|
||||
printf("Selection not found after table manipulation!\n");
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
107
mozilla/editor/base/EditTxn.cpp
Normal file
107
mozilla/editor/base/EditTxn.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL") you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID);
|
||||
|
||||
NS_IMPL_ADDREF(EditTxn)
|
||||
NS_IMPL_RELEASE(EditTxn)
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
EditTxn::EditTxn()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
EditTxn::~EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::Do(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::Undo(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::Redo(void)
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITransactionIID)) {
|
||||
*aInstancePtr = (void*)(nsITransaction*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
*aInstancePtr = 0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
66
mozilla/editor/base/EditTxn.h
Normal file
66
mozilla/editor/base/EditTxn.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef EditTxn_h__
|
||||
#define EditTxn_h__
|
||||
|
||||
#include "nsITransaction.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define EDIT_TXN_CID \
|
||||
{/* c5ea31b0-ac48-11d2-86d8-000064657374 */ \
|
||||
0xc5ea31b0, 0xac48, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* base class for all document editing transactions.
|
||||
* provides default concrete behavior for all nsITransaction methods.
|
||||
* EditTxns optionally have a name. This name is for internal purposes only,
|
||||
* it is never seen by the user or by any external entity.
|
||||
*/
|
||||
class EditTxn : public nsITransaction
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = EDIT_TXN_CID; return iid; }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
EditTxn();
|
||||
virtual ~EditTxn();
|
||||
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
112
mozilla/editor/base/IMECommitTxn.cpp
Normal file
112
mozilla/editor/base/IMECommitTxn.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "IMECommitTxn.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
nsIAtom *IMECommitTxn::gIMECommitTxnName = nsnull;
|
||||
|
||||
nsresult IMECommitTxn::ClassInit()
|
||||
{
|
||||
if (nsnull==gIMECommitTxnName)
|
||||
gIMECommitTxnName = NS_NewAtom("NS_IMECommitTxn");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
IMECommitTxn::IMECommitTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
IMECommitTxn::~IMECommitTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Init(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Do(void)
|
||||
{
|
||||
#ifdef DEBUG_tague
|
||||
printf("Do IME Commit");
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Undo(void)
|
||||
{
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Undo IME Commit");
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Merge IME Commit");
|
||||
#endif
|
||||
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove IMECommit: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert IMECommit: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* ============= nsISupports implementation ====================== */
|
||||
|
||||
NS_IMETHODIMP
|
||||
IMECommitTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(IMECommitTxn::GetCID())) {
|
||||
*aInstancePtr = (void*)(IMECommitTxn*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return (EditTxn::QueryInterface(aIID, aInstancePtr));
|
||||
}
|
||||
|
||||
|
||||
82
mozilla/editor/base/IMECommitTxn.h
Normal file
82
mozilla/editor/base/IMECommitTxn.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef IMECommitTxn_h__
|
||||
#define IMECommitTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// {9C4994A1-281C-11d3-9EA3-0060089FE59B}
|
||||
#define IME_COMMIT_TXN_CID \
|
||||
{ 0x9c4994a1, 0x281c, 0x11d3, \
|
||||
{ 0x9e, 0xa3, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
/**
|
||||
* A transaction representing an IME commit operation
|
||||
*/
|
||||
class IMECommitTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetCID() { static nsIID iid = IME_COMMIT_TXN_CID; return iid; }
|
||||
|
||||
virtual ~IMECommitTxn();
|
||||
|
||||
static nsIAtom *gIMECommitTxnName;
|
||||
|
||||
/** initialize the transaction
|
||||
*/
|
||||
NS_IMETHOD Init(void);
|
||||
|
||||
private:
|
||||
|
||||
IMECommitTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
// nsISupports declarations
|
||||
|
||||
// override QueryInterface to handle IMECommitTxn request
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
/** must be called before any IMECommitTxn is instantiated */
|
||||
static nsresult ClassInit();
|
||||
|
||||
protected:
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
friend class nsDerivedSafe<IMECommitTxn>; // work around for a compiler bug
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
310
mozilla/editor/base/IMETextTxn.cpp
Normal file
310
mozilla/editor/base/IMETextTxn.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "IMETextTxn.h"
|
||||
#include "IMECommitTxn.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMTextRange.h"
|
||||
#include "nsIDOMTextRangeList.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "EditAggregateTxn.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
||||
|
||||
nsIAtom *IMETextTxn::gIMETextTxnName = nsnull;
|
||||
|
||||
nsresult IMETextTxn::ClassInit()
|
||||
{
|
||||
if (nsnull==gIMETextTxnName)
|
||||
gIMETextTxnName = NS_NewAtom("NS_IMETextTxn");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
IMETextTxn::IMETextTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
IMETextTxn::~IMETextTxn()
|
||||
{
|
||||
mRangeList = do_QueryInterface(nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aReplaceLength,
|
||||
nsIDOMTextRangeList* aTextRangeList,
|
||||
const nsString &aStringToInsert,
|
||||
nsIPresShell *aPresShell)
|
||||
{
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mOffset = aOffset;
|
||||
mReplaceLength = aReplaceLength;
|
||||
mStringToInsert = aStringToInsert;
|
||||
mPresShell = aPresShell;
|
||||
mRangeList = do_QueryInterface(aTextRangeList);
|
||||
mFixed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Do(void)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Do IME Text element = %p\n", mElement.get());
|
||||
#endif
|
||||
|
||||
// advance caret: This requires the presentation shell to get the selection.
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
NS_ASSERTION(selection,"Could not get selection in IMEtextTxn::Do\n");
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
if (mReplaceLength==0) {
|
||||
result = mElement->InsertData(mOffset,mStringToInsert);
|
||||
} else {
|
||||
result = mElement->ReplaceData(mOffset,mReplaceLength,mStringToInsert);
|
||||
}
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = CollapseTextSelection();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Undo(void)
|
||||
{
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Undo IME Text element = %p\n", mElement.get());
|
||||
#endif
|
||||
|
||||
nsresult result;
|
||||
PRUint32 length = mStringToInsert.Length();
|
||||
result = mElement->DeleteData(mOffset, length);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{ // set the selection to the insertion point where the string was removed
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
nsresult result;
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Merge IME Text element = %p\n", mElement.get());
|
||||
#endif
|
||||
|
||||
//
|
||||
// check to make sure we have valid return pointers
|
||||
//
|
||||
if ((nsnull==aDidMerge) && (nsnull==aTransaction))
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// check to make sure we aren't fixed, if we are then nothing get's absorbed
|
||||
//
|
||||
if (mFixed) {
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// if aTransaction is another IMETextTxn then absorbe it
|
||||
//
|
||||
IMETextTxn* otherTxn = nsnull;
|
||||
result = aTransaction->QueryInterface(IMETextTxn::GetCID(),(void**)&otherTxn);
|
||||
if (otherTxn && result==NS_OK)
|
||||
{
|
||||
//
|
||||
// we absorbe the next IME transaction by adopting it's insert string as our own
|
||||
//
|
||||
nsIDOMTextRangeList* newTextRangeList;
|
||||
otherTxn->GetData(mStringToInsert,&newTextRangeList);
|
||||
mRangeList = do_QueryInterface(newTextRangeList);
|
||||
*aDidMerge = PR_TRUE;
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("IMETextTxn assimilated IMETextTxn:%p\n", aTransaction);
|
||||
#endif
|
||||
NS_RELEASE(otherTxn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// second possible case is that we have a commit transaction
|
||||
//
|
||||
IMECommitTxn* commitTxn = nsnull;
|
||||
result = aTransaction->QueryInterface(IMECommitTxn::GetCID(),(void**)&commitTxn);
|
||||
if (commitTxn && result==NS_OK)
|
||||
{
|
||||
(void)CollapseTextSelectionOnCommit();
|
||||
mFixed = PR_TRUE;
|
||||
*aDidMerge = PR_TRUE; // absorbe the commit transaction
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("IMETextTxn assimilated IMECommitTxn%p\n", aTransaction);
|
||||
#endif
|
||||
NS_RELEASE(commitTxn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Text: ";
|
||||
*aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Text: ";
|
||||
*aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* ============= nsISupports implementation ====================== */
|
||||
|
||||
NS_IMETHODIMP
|
||||
IMETextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(IMETextTxn::GetCID())) {
|
||||
*aInstancePtr = (void*)(IMETextTxn*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return (EditTxn::QueryInterface(aIID, aInstancePtr));
|
||||
}
|
||||
|
||||
/* ============ protected methods ================== */
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIDOMTextRangeList** aTextRangeList)
|
||||
{
|
||||
aResult = mStringToInsert;
|
||||
*aTextRangeList = mRangeList;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void)
|
||||
{
|
||||
nsresult result;
|
||||
PRBool haveSelectedRange, haveCaretPosition;
|
||||
PRUint16 textRangeListLength,selectionStart,selectionEnd,
|
||||
textRangeType, caretPosition, i;
|
||||
nsIDOMTextRange* textRange;
|
||||
|
||||
haveSelectedRange = PR_FALSE;
|
||||
haveCaretPosition = PR_FALSE;
|
||||
|
||||
|
||||
#ifdef DEBUG_tague
|
||||
PRUint16 listlen,start,stop,type;
|
||||
nsIDOMTextRange* rangePtr;
|
||||
result = mRangeList->GetLength(&listlen);
|
||||
printf("nsIDOMTextRangeList[%p]\n",mRangeList);
|
||||
for (i=0;i<listlen;i++) {
|
||||
(void)mRangeList->Item(i,&rangePtr);
|
||||
rangePtr->GetRangeStart(&start);
|
||||
rangePtr->GetRangeEnd(&stop);
|
||||
rangePtr->GetRangeType(&type);
|
||||
printf("range[%d] start=%d end=%d type=",i,start,stop,type);
|
||||
if (type==nsIDOMTextRange::TEXTRANGE_RAWINPUT) printf("TEXTRANGE_RAWINPUT\n");
|
||||
if (type==nsIDOMTextRange::TEXTRANGE_SELECTEDRAWTEXT) printf("TEXTRANGE_SELECTEDRAWTEXT\n");
|
||||
if (type==nsIDOMTextRange::TEXTRANGE_CONVERTEDTEXT) printf("TEXTRANGE_CONVERTEDTEXT\n");
|
||||
if (type==nsIDOMTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT) printf("TEXTRANGE_SELECTEDCONVERTEDTEXT\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// run through the text range list
|
||||
//
|
||||
result = mRangeList->GetLength(&textRangeListLength);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
for(i=0;i<textRangeListLength;i++) {
|
||||
result = mRangeList->Item(i,&textRange);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = textRange->GetRangeType(&textRangeType);
|
||||
if (textRangeType==nsIDOMTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT)
|
||||
{
|
||||
haveSelectedRange = PR_TRUE;
|
||||
textRange->GetRangeStart(&selectionStart);
|
||||
textRange->GetRangeEnd(&selectionEnd);
|
||||
}
|
||||
if (textRangeType==nsIDOMTextRange::TEXTRANGE_CARETPOSITION)
|
||||
{
|
||||
haveCaretPosition = PR_TRUE;
|
||||
textRange->GetRangeStart(&caretPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection){
|
||||
if (haveSelectedRange) {
|
||||
result = selection->Collapse(mElement,mOffset+selectionStart);
|
||||
result = selection->Extend(mElement,mOffset+selectionEnd);
|
||||
} else {
|
||||
if (haveCaretPosition)
|
||||
result = selection->Collapse(mElement,mOffset+caretPosition);
|
||||
else
|
||||
result = selection->Collapse(mElement,mOffset+mStringToInsert.Length());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::CollapseTextSelectionOnCommit(void)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection){
|
||||
result = selection->Collapse(mElement,mOffset+mStringToInsert.Length());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
125
mozilla/editor/base/IMETextTxn.h
Normal file
125
mozilla/editor/base/IMETextTxn.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef IMETextTxn_h__
|
||||
#define IMETextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMTextRangeList.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// {D4D25721-2813-11d3-9EA3-0060089FE59B}
|
||||
#define IME_TEXT_TXN_CID \
|
||||
{0xd4d25721, 0x2813, 0x11d3, \
|
||||
{0x9e, 0xa3, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
|
||||
|
||||
class nsIPresShell;
|
||||
|
||||
/**
|
||||
* A transaction that inserts text into a content node.
|
||||
*/
|
||||
class IMETextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetCID() { static nsIID iid = IME_TEXT_TXN_CID; return iid; }
|
||||
|
||||
virtual ~IMETextTxn();
|
||||
|
||||
/** used to name aggregate transactions that consist only of a single IMETextTxn,
|
||||
* or a DeleteSelection followed by an IMETextTxn.
|
||||
*/
|
||||
static nsIAtom *gIMETextTxnName;
|
||||
|
||||
/** initialize the transaction
|
||||
* @param aElement the text content node
|
||||
* @param aOffset the location in aElement to do the insertion
|
||||
* @param aReplaceLength the length of text to replace (0= no replacement)
|
||||
* @param aString the new text to insert
|
||||
* @param aPresShell used to get and set the selection
|
||||
*/
|
||||
NS_IMETHOD Init(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aReplaceLength,
|
||||
nsIDOMTextRangeList* aTextRangeList,
|
||||
const nsString& aString,
|
||||
nsIPresShell* aPresShell);
|
||||
|
||||
private:
|
||||
|
||||
IMETextTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
// nsISupports declarations
|
||||
|
||||
// override QueryInterface to handle IMETextTxn request
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
/** return the string data associated with this transaction */
|
||||
NS_IMETHOD GetData(nsString& aResult, nsIDOMTextRangeList** aTextRangeList);
|
||||
|
||||
/** must be called before any IMETextTxn is instantiated */
|
||||
static nsresult ClassInit();
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD CollapseTextSelection(void);
|
||||
NS_IMETHOD CollapseTextSelectionOnCommit(void);
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsCOMPtr<nsIDOMCharacterData> mElement;
|
||||
|
||||
/** the offsets into mElement where the insertion should be placed*/
|
||||
PRUint32 mOffset;
|
||||
|
||||
PRUint32 mReplaceLength;
|
||||
|
||||
/** the text to insert into mElement at mOffset */
|
||||
nsString mStringToInsert;
|
||||
|
||||
/** the range list **/
|
||||
nsCOMPtr<nsIDOMTextRangeList> mRangeList;
|
||||
|
||||
/** the presentation shell, which we'll need to get the selection */
|
||||
nsIPresShell* mPresShell;
|
||||
|
||||
PRBool mFixed;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
friend class nsDerivedSafe<IMETextTxn>; // work around for a compiler bug
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
148
mozilla/editor/base/InsertElementTxn.cpp
Normal file
148
mozilla/editor/base/InsertElementTxn.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "InsertElementTxn.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
|
||||
InsertElementTxn::InsertElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::Init(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aOffset,
|
||||
nsIEditor *aEditor)
|
||||
{
|
||||
NS_ASSERTION(aNode && aParent && aEditor, "bad arg");
|
||||
if (!aNode || !aParent || !aEditor)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mNode = do_QueryInterface(aNode);
|
||||
mParent = do_QueryInterface(aParent);
|
||||
mOffset = aOffset;
|
||||
mEditor = aEditor;
|
||||
if (!mNode || !mParent || !mEditor)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
InsertElementTxn::~InsertElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::Do(void)
|
||||
{
|
||||
if (gNoisy)
|
||||
{
|
||||
nsCOMPtr<nsIContent>nodeAsContent = do_QueryInterface(mNode);
|
||||
nsCOMPtr<nsIContent>parentAsContent = do_QueryInterface(mParent);
|
||||
printf("%p Do Insert Element of %p into parent %p at offset %d\n",
|
||||
this, nodeAsContent.get(), parentAsContent.get(), mOffset);
|
||||
}
|
||||
if (!mNode || !mParent)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode>refNode;
|
||||
//if (0!=mOffset)
|
||||
{ // get a ref node
|
||||
PRInt32 i=0;
|
||||
result = mParent->GetFirstChild(getter_AddRefs(refNode));
|
||||
if (NS_SUCCEEDED(result) && refNode)
|
||||
{
|
||||
for (; i<mOffset; i++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>nextSib;
|
||||
result = refNode->GetNextSibling(getter_AddRefs(nextSib));
|
||||
if (NS_FAILED(result)) {
|
||||
break; // couldn't get a next sibling, so make aNode the first child
|
||||
}
|
||||
refNode = do_QueryInterface(nextSib);
|
||||
if (!refNode) {
|
||||
break; // couldn't get a next sibling, so make aNode the first child
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result) && resultNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if ((NS_SUCCEEDED(result)) && selection)
|
||||
{ // place the selection just after the inserted element
|
||||
selection->Collapse(mParent, mOffset+1);
|
||||
//selection->Extend(mParent, mOffset+1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Undo Insert Element of %p into parent %p at offset %d\n",
|
||||
this, mNode.get(), mParent.get(), mOffset); }
|
||||
if (!mNode || !mParent)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->RemoveChild(mNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Element: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertElementTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Element: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
88
mozilla/editor/base/InsertElementTxn.h
Normal file
88
mozilla/editor/base/InsertElementTxn.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef InsertElementTxn_h__
|
||||
#define InsertElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define INSERT_ELEMENT_TXN_CID \
|
||||
{/* b5762440-cbb0-11d2-86db-000064657374 */ \
|
||||
0xb5762440, 0xcbb0, 0x11d2, \
|
||||
{0x86, 0xdb, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that inserts a single element
|
||||
*/
|
||||
class InsertElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = INSERT_ELEMENT_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aNode the node to insert
|
||||
* @param aParent the node to insert into
|
||||
* @param aOffset the offset in aParent to insert aNode
|
||||
*/
|
||||
NS_IMETHOD Init(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aOffset,
|
||||
nsIEditor *aEditor);
|
||||
|
||||
private:
|
||||
InsertElementTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~InsertElementTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the element to insert */
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
|
||||
/** the node into which the new node will be inserted */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
|
||||
/** the editor for this transaction */
|
||||
nsIEditor* mEditor;
|
||||
|
||||
/** the index in mParent for the new node */
|
||||
PRInt32 mOffset;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
235
mozilla/editor/base/InsertTextTxn.cpp
Normal file
235
mozilla/editor/base/InsertTextTxn.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "InsertTextTxn.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "EditAggregateTxn.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
nsIAtom *InsertTextTxn::gInsertTextTxnName;
|
||||
|
||||
nsresult InsertTextTxn::ClassInit()
|
||||
{
|
||||
if (nsnull==gInsertTextTxnName)
|
||||
gInsertTextTxnName = NS_NewAtom("NS_InsertTextTxn");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
InsertTextTxn::InsertTextTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
InsertTextTxn::~InsertTextTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString &aStringToInsert,
|
||||
nsIPresShell *aPresShell)
|
||||
{
|
||||
#if 0 //def DEBUG_cmanske
|
||||
nsString text;
|
||||
aElement->GetData(text);
|
||||
printf("InsertTextTxn: Offset to insert at = %d. Text of the node to insert into:\n", aOffset);
|
||||
wprintf(text.GetUnicode());
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mOffset = aOffset;
|
||||
mStringToInsert = aStringToInsert;
|
||||
mPresShell = aPresShell;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("Do Insert Text element = %p\n", mElement.get()); }
|
||||
// advance caret: This requires the presentation shell to get the selection.
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n");
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
result = mElement->InsertData(mOffset, mStringToInsert);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("Undo Insert Text element = %p\n", mElement.get()); }
|
||||
nsresult result;
|
||||
PRUint32 length = mStringToInsert.Length();
|
||||
result = mElement->DeleteData(mOffset, length);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{ // set the selection to the insertion point where the string was removed
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
nsresult result = NS_OK;
|
||||
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
|
||||
{
|
||||
// if aTransaction isa InsertTextTxn, and if the selection hasn't changed,
|
||||
// then absorb it
|
||||
InsertTextTxn *otherInsTxn = nsnull;
|
||||
aTransaction->QueryInterface(InsertTextTxn::GetCID(), (void **)&otherInsTxn);
|
||||
if (otherInsTxn)
|
||||
{
|
||||
if (PR_TRUE==IsSequentialInsert(otherInsTxn))
|
||||
{
|
||||
nsAutoString otherData;
|
||||
otherInsTxn->GetData(otherData);
|
||||
mStringToInsert += otherData;
|
||||
*aDidMerge = PR_TRUE;
|
||||
if (gNoisy) { printf("InsertTextTxn assimilated %p\n", aTransaction); }
|
||||
}
|
||||
NS_RELEASE(otherInsTxn);
|
||||
}
|
||||
else
|
||||
{ // the next InsertTextTxn might be inside an aggregate that we have special knowledge of
|
||||
EditAggregateTxn *otherTxn = nsnull;
|
||||
aTransaction->QueryInterface(EditAggregateTxn::GetCID(), (void **)&otherTxn);
|
||||
if (otherTxn)
|
||||
{
|
||||
nsCOMPtr<nsIAtom> txnName;
|
||||
otherTxn->GetName(getter_AddRefs(txnName));
|
||||
if (txnName && txnName.get()==gInsertTextTxnName)
|
||||
{ // yep, it's one of ours. By definition, it must contain only
|
||||
// another aggregate with a single child,
|
||||
// or a single InsertTextTxn
|
||||
nsCOMPtr<EditTxn> childTxn;
|
||||
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
|
||||
if (childTxn)
|
||||
{
|
||||
nsCOMPtr<InsertTextTxn> otherInsertTxn;
|
||||
otherInsertTxn = do_QueryInterface(childTxn);
|
||||
if (otherInsertTxn)
|
||||
{
|
||||
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
|
||||
{
|
||||
nsAutoString otherData;
|
||||
otherInsertTxn->GetData(otherData);
|
||||
mStringToInsert += otherData;
|
||||
*aDidMerge = PR_TRUE;
|
||||
if (gNoisy) { printf("InsertTextTxn assimilated %p\n", aTransaction); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(otherTxn);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Text: ";
|
||||
*aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Text: ";
|
||||
*aString += mStringToInsert;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* ============= nsISupports implementation ====================== */
|
||||
|
||||
NS_IMETHODIMP
|
||||
InsertTextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(InsertTextTxn::GetCID())) {
|
||||
*aInstancePtr = (void*)(InsertTextTxn*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return (EditTxn::QueryInterface(aIID, aInstancePtr));
|
||||
}
|
||||
|
||||
/* ============ protected methods ================== */
|
||||
|
||||
NS_IMETHODIMP InsertTextTxn::GetData(nsString& aResult)
|
||||
{
|
||||
aResult = mStringToInsert;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool InsertTextTxn::IsSequentialInsert(InsertTextTxn *aOtherTxn)
|
||||
{
|
||||
NS_ASSERTION(nsnull!=aOtherTxn, "null param");
|
||||
PRBool result=PR_FALSE;
|
||||
if (nsnull!=aOtherTxn)
|
||||
{
|
||||
if (aOtherTxn->mElement == mElement)
|
||||
{
|
||||
// here, we need to compare offsets.
|
||||
PRInt32 length = mStringToInsert.Length();
|
||||
if (aOtherTxn->mOffset==(mOffset+length))
|
||||
{
|
||||
result = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
112
mozilla/editor/base/InsertTextTxn.h
Normal file
112
mozilla/editor/base/InsertTextTxn.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef InsertTextTxn_h__
|
||||
#define InsertTextTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define INSERT_TEXT_TXN_CID \
|
||||
{/* 93276f00-ab2c-11d2-8f4b-006008159b0c*/ \
|
||||
0x93276f00, 0xab2c, 0x11d2, \
|
||||
{0x8f, 0xb4, 0x0, 0x60, 0x8, 0x15, 0x9b, 0xc} }
|
||||
|
||||
class nsIPresShell;
|
||||
|
||||
/**
|
||||
* A transaction that inserts text into a content node.
|
||||
*/
|
||||
class InsertTextTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = INSERT_TEXT_TXN_CID; return iid; }
|
||||
|
||||
virtual ~InsertTextTxn();
|
||||
|
||||
/** used to name aggregate transactions that consist only of a single InsertTextTxn,
|
||||
* or a DeleteSelection followed by an InsertTextTxn.
|
||||
*/
|
||||
static nsIAtom *gInsertTextTxnName;
|
||||
|
||||
/** initialize the transaction
|
||||
* @param aElement the text content node
|
||||
* @param aOffset the location in aElement to do the insertion
|
||||
* @param aString the new text to insert
|
||||
* @param aPresShell used to get and set the selection
|
||||
*/
|
||||
NS_IMETHOD Init(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
const nsString& aString,
|
||||
nsIPresShell* aPresShell);
|
||||
|
||||
private:
|
||||
|
||||
InsertTextTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
// nsISupports declarations
|
||||
|
||||
// override QueryInterface to handle InsertTextTxn request
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
/** return the string data associated with this transaction */
|
||||
NS_IMETHOD GetData(nsString& aResult);
|
||||
|
||||
/** must be called before any InsertTextTxn is instantiated */
|
||||
static nsresult ClassInit();
|
||||
|
||||
protected:
|
||||
|
||||
/** return PR_TRUE if aOtherTxn immediately follows this txn */
|
||||
virtual PRBool IsSequentialInsert(InsertTextTxn *aOtherTxn);
|
||||
|
||||
/** the text element to operate upon */
|
||||
nsCOMPtr<nsIDOMCharacterData> mElement;
|
||||
|
||||
/** the offset into mElement where the insertion is to take place */
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the text to insert into mElement at mOffset */
|
||||
nsString mStringToInsert;
|
||||
|
||||
/** the presentation shell, which we'll need to get the selection */
|
||||
nsIPresShell* mPresShell;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
friend class nsDerivedSafe<InsertTextTxn>; // work around for a compiler bug
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
181
mozilla/editor/base/JoinElementTxn.cpp
Normal file
181
mozilla/editor/base/JoinElementTxn.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "JoinElementTxn.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
JoinElementTxn::JoinElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP JoinElementTxn::Init(nsIEditor *aEditor,
|
||||
nsIDOMNode *aLeftNode,
|
||||
nsIDOMNode *aRightNode)
|
||||
{
|
||||
mEditor = aEditor;
|
||||
mLeftNode = do_QueryInterface(aLeftNode);
|
||||
mRightNode = do_QueryInterface(aRightNode);
|
||||
mOffset=0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JoinElementTxn::~JoinElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
// After Do() and Redo(), the left node is removed from the content tree and right node remains.
|
||||
NS_IMETHODIMP JoinElementTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Do Join of %p and %p\n", this, mLeftNode.get(), mRightNode.get()); }
|
||||
nsresult result;
|
||||
|
||||
if ((mLeftNode) && (mRightNode))
|
||||
{ // get the parent node
|
||||
nsCOMPtr<nsIDOMNode>leftParent;
|
||||
result = mLeftNode->GetParentNode(getter_AddRefs(leftParent));
|
||||
if ((NS_SUCCEEDED(result)) && (leftParent))
|
||||
{ // verify that mLeftNode and mRightNode have the same parent
|
||||
nsCOMPtr<nsIDOMNode>rightParent;
|
||||
result = mRightNode->GetParentNode(getter_AddRefs(rightParent));
|
||||
if ((NS_SUCCEEDED(result)) && (rightParent))
|
||||
{
|
||||
if (leftParent==rightParent)
|
||||
{
|
||||
mParent= do_QueryInterface(leftParent); // set this instance mParent.
|
||||
// Other methods will see a non-null mParent and know all is well
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
result = mLeftNode->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if ((NS_SUCCEEDED(result)) && (childNodes)) {
|
||||
childNodes->GetLength(&mOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData> leftNodeAsText;
|
||||
leftNodeAsText = do_QueryInterface(mLeftNode);
|
||||
if (leftNodeAsText) {
|
||||
leftNodeAsText->GetLength(&mOffset);
|
||||
}
|
||||
}
|
||||
result = nsEditor::JoinNodesImpl(mRightNode, mLeftNode, mParent, PR_FALSE);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (gNoisy) { printf(" left node = %p removed\n", mLeftNode.get()); }
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (selection)
|
||||
{
|
||||
selection->Collapse(mRightNode, mOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "2 nodes do not have same parent");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//XXX: what if instead of split, we just deleted the unneeded children of mRight
|
||||
// and re-inserted mLeft?
|
||||
NS_IMETHODIMP JoinElementTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Undo Join, right node = %p\n", this, mRightNode.get()); }
|
||||
NS_ASSERTION(mRightNode && mLeftNode && mParent, "bad state");
|
||||
if (!mRightNode || !mLeftNode || !mParent) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode>resultNode;
|
||||
// first, massage the existing node so it is in its post-split state
|
||||
nsCOMPtr<nsIDOMCharacterData>rightNodeAsText;
|
||||
rightNodeAsText = do_QueryInterface(mRightNode);
|
||||
if (rightNodeAsText)
|
||||
{
|
||||
result = rightNodeAsText->DeleteData(0, mOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>child;
|
||||
nsCOMPtr<nsIDOMNode>nextSibling;
|
||||
result = mRightNode->GetFirstChild(getter_AddRefs(child));
|
||||
PRUint32 i;
|
||||
for (i=0; i<mOffset; i++)
|
||||
{
|
||||
if (NS_FAILED(result)) {return result;}
|
||||
if (!child) {return NS_ERROR_NULL_POINTER;}
|
||||
child->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
result = mLeftNode->AppendChild(child, getter_AddRefs(resultNode));
|
||||
child = do_QueryInterface(nextSibling);
|
||||
}
|
||||
}
|
||||
// second, re-insert the left node into the tree
|
||||
result = mParent->InsertBefore(mLeftNode, mRightNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP JoinElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult JoinElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP JoinElementTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP JoinElementTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Join Element";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP JoinElementTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Split Element";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
98
mozilla/editor/base/JoinElementTxn.h
Normal file
98
mozilla/editor/base/JoinElementTxn.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef JoinElementTxn_h__
|
||||
#define JoinElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEditor.h"
|
||||
|
||||
#define JOIN_ELEMENT_TXN_CID \
|
||||
{/* 9bc5f9f0-ac48-11d2-86d8-000064657374 */ \
|
||||
0x9bc5f9f0, 0xac48, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
|
||||
/**
|
||||
* A transaction that joins two elements E1 (left node) and E2 (right node)
|
||||
* into a single node E.
|
||||
* The children of E are the children of E1 followed by the children of E2.
|
||||
* After Do() and Redo(), E1 is removed from the content tree and E2 remains.
|
||||
*/
|
||||
class JoinElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = JOIN_ELEMENT_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction
|
||||
* @param aEditor the provider of core editing operations
|
||||
* @param aLeftNode the first of two nodes to join
|
||||
* @param aRightNode the second of two nodes to join
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
nsIDOMNode *aLeftNode,
|
||||
nsIDOMNode *aRightNode);
|
||||
protected:
|
||||
JoinElementTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~JoinElementTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
// NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the elements to operate upon.
|
||||
* After the merge, mRightNode remains and mLeftNode is removed from the content tree.
|
||||
*/
|
||||
nsCOMPtr<nsIDOMNode> mLeftNode;
|
||||
nsCOMPtr<nsIDOMNode> mRightNode;
|
||||
|
||||
/** the offset into mNode where the children of mElement are split (for undo).<BR>
|
||||
* mOffset is the index of the first child in the right node.
|
||||
* -1 means the left node had no children.
|
||||
*/
|
||||
PRUint32 mOffset;
|
||||
|
||||
/** the parent node containing mLeftNode and mRightNode */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
nsIEditor* mEditor;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
78
mozilla/editor/base/Makefile.in
Normal file
78
mozilla/editor/base/Makefile.in
Normal file
@@ -0,0 +1,78 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = ender
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsEditor.cpp \
|
||||
nsEditorUtils.cpp \
|
||||
nsEditorRegistration.cpp \
|
||||
nsTextEditRules.cpp \
|
||||
TextEditorTest.cpp \
|
||||
nsHTMLEditRules.cpp \
|
||||
nsEditorEventListeners.cpp \
|
||||
nsEditProperty.cpp \
|
||||
nsEditorFactory.cpp \
|
||||
nsHTMLEditor.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
EditTxn.cpp \
|
||||
EditAggregateTxn.cpp \
|
||||
EditTable.cpp \
|
||||
InsertTextTxn.cpp \
|
||||
nsInsertHTMLTxn.cpp \
|
||||
PlaceholderTxn.cpp \
|
||||
DeleteTextTxn.cpp \
|
||||
CreateElementTxn.cpp \
|
||||
InsertElementTxn.cpp \
|
||||
DeleteElementTxn.cpp \
|
||||
DeleteRangeTxn.cpp \
|
||||
SplitElementTxn.cpp \
|
||||
JoinElementTxn.cpp \
|
||||
nsStyleSheetTxns.cpp \
|
||||
TransactionFactory.cpp \
|
||||
TypeInState.cpp \
|
||||
nsInternetCiter.cpp \
|
||||
nsAOLCiter.cpp \
|
||||
nsInterfaceState.cpp \
|
||||
nsEditorShell.cpp \
|
||||
nsEditorShellFactory.cpp \
|
||||
IMETextTxn.cpp \
|
||||
IMECommitTxn.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_JS_EDITOR_LOG
|
||||
DEFINES += -DENABLE_JS_EDITOR_LOG
|
||||
CPPSRCS += \
|
||||
nsJSEditorLog.cpp \
|
||||
nsJSTxnLog.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
MODULE = editor
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
76
mozilla/editor/base/PlaceholderTxn.cpp
Normal file
76
mozilla/editor/base/PlaceholderTxn.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "PlaceholderTxn.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_TRUE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
|
||||
PlaceholderTxn::PlaceholderTxn()
|
||||
: EditAggregateTxn()
|
||||
{
|
||||
mAbsorb=PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
PlaceholderTxn::~PlaceholderTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PlaceholderTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("PlaceholderTxn Do\n"); }
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PlaceholderTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
nsresult result = NS_OK;
|
||||
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
|
||||
{
|
||||
EditTxn *editTxn = (EditTxn*)aTransaction; //XXX: hack, not safe! need nsIEditTransaction!
|
||||
if (PR_TRUE==mAbsorb)
|
||||
{ // yep, it's one of ours. Assimilate it.
|
||||
AppendChild(editTxn);
|
||||
*aDidMerge = PR_TRUE;
|
||||
if (gNoisy) { printf("Placeholder txn assimilated %p\n", aTransaction); }
|
||||
}
|
||||
else
|
||||
{ // let our last child txn make the choice
|
||||
PRInt32 count = mChildren->Count();
|
||||
if (0<count)
|
||||
{
|
||||
EditTxn *lastTxn = (EditTxn*)(mChildren->ElementAt(count-1));
|
||||
if (lastTxn)
|
||||
{
|
||||
lastTxn->Merge(aDidMerge, aTransaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
69
mozilla/editor/base/PlaceholderTxn.h
Normal file
69
mozilla/editor/base/PlaceholderTxn.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef AggregatePlaceholderTxn_h__
|
||||
#define AggregatePlaceholderTxn_h__
|
||||
|
||||
#include "EditAggregateTxn.h"
|
||||
|
||||
#define PLACEHOLDER_TXN_CID \
|
||||
{/* {0CE9FB00-D9D1-11d2-86DE-000064657374} */ \
|
||||
0x0CE9FB00, 0xD9D1, 0x11d2, \
|
||||
{0x86, 0xde, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* An aggregate transaction that knows how to absorb all subsequent
|
||||
* transactions with the same name. This transaction does not "Do" anything.
|
||||
* But it absorbs other transactions via merge, and can undo/redo the
|
||||
* transactions it has absorbed.
|
||||
*/
|
||||
class PlaceholderTxn : public EditAggregateTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = PLACEHOLDER_TXN_CID; return iid; }
|
||||
|
||||
private:
|
||||
PlaceholderTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~PlaceholderTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD SetAbsorb(PRBool aAbsorb);
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
protected:
|
||||
|
||||
PRBool mAbsorb;
|
||||
|
||||
};
|
||||
|
||||
inline NS_IMETHODIMP PlaceholderTxn::SetAbsorb(PRBool aAbsorb)
|
||||
{
|
||||
mAbsorb = aAbsorb;
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
226
mozilla/editor/base/SplitElementTxn.cpp
Normal file
226
mozilla/editor/base/SplitElementTxn.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "SplitElementTxn.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
SplitElementTxn::SplitElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Init(nsIEditor *aEditor,
|
||||
nsIDOMNode *aNode,
|
||||
PRInt32 aOffset)
|
||||
{
|
||||
mEditor = aEditor;
|
||||
mExistingRightNode = do_QueryInterface(aNode);
|
||||
mOffset = aOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
SplitElementTxn::~SplitElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Do(void)
|
||||
{
|
||||
if (gNoisy) { printf("%p Do Split of node %p offset %d\n", this, mExistingRightNode.get(), mOffset); }
|
||||
NS_ASSERTION(mExistingRightNode, "bad state");
|
||||
if (!mExistingRightNode) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
// create a new node
|
||||
nsresult result = mExistingRightNode->CloneNode(PR_FALSE, getter_AddRefs(mNewLeftNode));
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewLeftNode)), "could not create element.");
|
||||
|
||||
if ((NS_SUCCEEDED(result)) && (mNewLeftNode))
|
||||
{
|
||||
if (gNoisy) { printf(" created left node = %p\n", mNewLeftNode.get()); }
|
||||
// get the parent node
|
||||
result = mExistingRightNode->GetParentNode(getter_AddRefs(mParent));
|
||||
// insert the new node
|
||||
if ((NS_SUCCEEDED(result)) && (mParent))
|
||||
{
|
||||
result = nsEditor::SplitNodeImpl(mExistingRightNode, mOffset, mNewLeftNode, mParent);
|
||||
if (NS_SUCCEEDED(result) && mNewLeftNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (selection)
|
||||
{
|
||||
selection->Collapse(mNewLeftNode, mOffset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Undo(void)
|
||||
{
|
||||
if (gNoisy) {
|
||||
printf("%p Undo Split of existing node %p and new node %p offset %d\n",
|
||||
this, mExistingRightNode.get(), mNewLeftNode.get(), mOffset);
|
||||
}
|
||||
NS_ASSERTION(mExistingRightNode && mNewLeftNode && mParent, "bad state");
|
||||
if (!mExistingRightNode || !mNewLeftNode || !mParent) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// this assumes Do inserted the new node in front of the prior existing node
|
||||
nsresult result;
|
||||
result = nsEditor::JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent, PR_FALSE);
|
||||
if (gNoisy)
|
||||
{
|
||||
printf("** after join left child node %p into right node %p\n", mNewLeftNode.get(), mExistingRightNode.get());
|
||||
if (gNoisy) {mEditor->DebugDumpContent(); } // DEBUG
|
||||
}
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (gNoisy) { printf(" left node = %p removed\n", mNewLeftNode.get()); }
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (selection)
|
||||
{
|
||||
selection->Collapse(mExistingRightNode, mOffset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* redo cannot simply resplit the right node, because subsequent transactions
|
||||
* on the redo stack may depend on the left node existing in its previous state.
|
||||
*/
|
||||
NS_IMETHODIMP SplitElementTxn::Redo(void)
|
||||
{
|
||||
NS_ASSERTION(mExistingRightNode && mNewLeftNode && mParent, "bad state");
|
||||
if (!mExistingRightNode || !mNewLeftNode || !mParent) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
if (gNoisy) {
|
||||
printf("%p Redo Split of existing node %p and new node %p offset %d\n",
|
||||
this, mExistingRightNode.get(), mNewLeftNode.get(), mOffset);
|
||||
if (gNoisy) {mEditor->DebugDumpContent(); } // DEBUG
|
||||
}
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode>resultNode;
|
||||
// first, massage the existing node so it is in its post-split state
|
||||
nsCOMPtr<nsIDOMCharacterData>rightNodeAsText;
|
||||
rightNodeAsText = do_QueryInterface(mExistingRightNode);
|
||||
if (rightNodeAsText)
|
||||
{
|
||||
result = rightNodeAsText->DeleteData(0, mOffset);
|
||||
if (gNoisy)
|
||||
{
|
||||
printf("** after delete of text in right text node %p offset %d\n", rightNodeAsText.get(), mOffset);
|
||||
if (gNoisy) {mEditor->DebugDumpContent(); } // DEBUG
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>child;
|
||||
nsCOMPtr<nsIDOMNode>nextSibling;
|
||||
result = mExistingRightNode->GetFirstChild(getter_AddRefs(child));
|
||||
PRInt32 i;
|
||||
for (i=0; i<mOffset; i++)
|
||||
{
|
||||
if (NS_FAILED(result)) {return result;}
|
||||
if (!child) {return NS_ERROR_NULL_POINTER;}
|
||||
child->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
result = mExistingRightNode->RemoveChild(child, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = mNewLeftNode->AppendChild(child, getter_AddRefs(resultNode));
|
||||
if (gNoisy)
|
||||
{
|
||||
printf("** move child node %p from right node %p to left node %p\n", child.get(), mExistingRightNode.get(), mNewLeftNode.get());
|
||||
if (gNoisy) {mEditor->DebugDumpContent(); } // DEBUG
|
||||
}
|
||||
}
|
||||
child = do_QueryInterface(nextSibling);
|
||||
}
|
||||
}
|
||||
// second, re-insert the left node into the tree
|
||||
result = mParent->InsertBefore(mNewLeftNode, mExistingRightNode, getter_AddRefs(resultNode));
|
||||
if (gNoisy)
|
||||
{
|
||||
printf("** reinsert left child node %p before right node %p\n", mNewLeftNode.get(), mExistingRightNode.get());
|
||||
if (gNoisy) {mEditor->DebugDumpContent(); } // DEBUG
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Join Element";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Split Element";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::GetNewNode(nsIDOMNode **aNewNode)
|
||||
{
|
||||
if (!aNewNode)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!mNewLeftNode)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
*aNewNode = mNewLeftNode;
|
||||
NS_ADDREF(*aNewNode);
|
||||
return NS_OK;
|
||||
}
|
||||
96
mozilla/editor/base/SplitElementTxn.h
Normal file
96
mozilla/editor/base/SplitElementTxn.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef SplitElementTxn_h__
|
||||
#define SplitElementTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEditor.h"
|
||||
|
||||
#define SPLIT_ELEMENT_TXN_CID \
|
||||
{/* 690c6290-ac48-11d2-86d8-000064657374 */ \
|
||||
0x690c6290, 0xac48, 0x11d2, \
|
||||
{0x86, 0xd8, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
/**
|
||||
* A transaction that splits an element E into two identical nodes, E1 and E2
|
||||
* with the children of E divided between E1 and E2.
|
||||
*/
|
||||
class SplitElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = SPLIT_ELEMENT_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aEditor the provider of core editing operations
|
||||
* @param aNode the node to split
|
||||
* @param aOffset the location within aNode to do the split.
|
||||
* aOffset may refer to children of aNode, or content of aNode.
|
||||
* The left node will have child|content 0..aOffset-1.
|
||||
*/
|
||||
NS_IMETHOD Init (nsIEditor *aEditor,
|
||||
nsIDOMNode *aNode,
|
||||
PRInt32 aOffset);
|
||||
protected:
|
||||
SplitElementTxn();
|
||||
|
||||
public:
|
||||
virtual ~SplitElementTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
|
||||
|
||||
protected:
|
||||
|
||||
/** the element to operate upon */
|
||||
nsCOMPtr<nsIDOMNode> mExistingRightNode;
|
||||
|
||||
/** the offset into mElement where the children of mElement are split.<BR>
|
||||
* mOffset is the index of the first child in the right node.
|
||||
* -1 means the new node gets no children.
|
||||
*/
|
||||
PRInt32 mOffset;
|
||||
|
||||
/** the element we create when splitting mElement */
|
||||
nsCOMPtr<nsIDOMNode> mNewLeftNode;
|
||||
|
||||
/** the parent shared by mExistingRightNode and mNewLeftNode */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
nsIEditor* mEditor;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
250
mozilla/editor/base/TextEditorTest.cpp
Normal file
250
mozilla/editor/base/TextEditorTest.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/* -*- Mode: C++ tab-width: 2 indent-tabs-mode: nil c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL") you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "TextEditorTest.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIEditProperty.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
||||
#define TEST_RESULT(r) { if (NS_FAILED(r)) {printf("FAILURE result=%X\n", r); return r; } }
|
||||
#define TEST_POINTER(p) { if (!p) {printf("FAILURE null pointer\n"); return NS_ERROR_NULL_POINTER; } }
|
||||
|
||||
TextEditorTest::TextEditorTest()
|
||||
{
|
||||
printf("constructed a TextEditorTest\n");
|
||||
}
|
||||
|
||||
TextEditorTest::~TextEditorTest()
|
||||
{
|
||||
printf("destroyed a TextEditorTest\n");
|
||||
}
|
||||
|
||||
void TextEditorTest::Run(nsIEditor *aEditor, PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
|
||||
{
|
||||
if (!aEditor) return;
|
||||
mTextEditor = do_QueryInterface(aEditor);
|
||||
mEditor = do_QueryInterface(aEditor);
|
||||
RunUnitTest(outNumTests, outNumTestsFailed);
|
||||
}
|
||||
|
||||
nsresult TextEditorTest::RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
if (!outNumTests || !outNumTestsFailed)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*outNumTests = 0;
|
||||
*outNumTestsFailed = 0;
|
||||
|
||||
result = InitDoc();
|
||||
TEST_RESULT(result);
|
||||
// shouldn't we just bail on error here?
|
||||
|
||||
// insert some simple text
|
||||
nsString docContent("1234567890abcdefghij1234567890");
|
||||
result = mTextEditor->InsertText(docContent);
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
|
||||
// insert some more text
|
||||
nsString docContent2("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere");
|
||||
result = mTextEditor->InsertText(docContent2);
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
|
||||
result = TestInsertBreak();
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
|
||||
result = TestTextProperties();
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
|
||||
// get us back to the original document
|
||||
result = mEditor->Undo(12);
|
||||
TEST_RESULT(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult TextEditorTest::InitDoc()
|
||||
{
|
||||
nsresult result = mEditor->SelectAll();
|
||||
TEST_RESULT(result);
|
||||
result = mEditor->DeleteSelection(nsIEditor::eDeleteNext);
|
||||
TEST_RESULT(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult TextEditorTest::TestInsertBreak()
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(selection.get());
|
||||
nsCOMPtr<nsIDOMNode>anchor;
|
||||
result = selection->GetAnchorNode(getter_AddRefs(anchor));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(anchor.get());
|
||||
selection->Collapse(anchor, 0);
|
||||
// insert one break
|
||||
printf("inserting a break\n");
|
||||
result = mTextEditor->InsertBreak();
|
||||
TEST_RESULT(result);
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
// insert a second break adjacent to the first
|
||||
printf("inserting a second break\n");
|
||||
result = mTextEditor->InsertBreak();
|
||||
TEST_RESULT(result);
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult TextEditorTest::TestTextProperties()
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
nsresult result = mEditor->GetDocument(getter_AddRefs(doc));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(doc.get());
|
||||
nsCOMPtr<nsIDOMNodeList>nodeList;
|
||||
nsAutoString textTag = "__moz_text";
|
||||
result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(nodeList.get());
|
||||
PRUint32 count;
|
||||
nodeList->GetLength(&count);
|
||||
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
|
||||
nsCOMPtr<nsIDOMNode>textNode;
|
||||
result = nodeList->Item(count-1, getter_AddRefs(textNode));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(textNode.get());
|
||||
|
||||
// set the whole text node to bold
|
||||
printf("set the whole first text node to bold\n");
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(selection.get());
|
||||
nsCOMPtr<nsIDOMCharacterData>textData;
|
||||
textData = do_QueryInterface(textNode);
|
||||
PRUint32 length;
|
||||
textData->GetLength(&length);
|
||||
selection->Collapse(textNode, 0);
|
||||
selection->Extend(textNode, length);
|
||||
PRBool any = PR_FALSE;
|
||||
PRBool all = PR_FALSE;
|
||||
PRBool first=PR_FALSE;
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_FALSE==first, "first should be false");
|
||||
NS_ASSERTION(PR_FALSE==any, "any should be false");
|
||||
NS_ASSERTION(PR_FALSE==all, "all should be false");
|
||||
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
|
||||
TEST_RESULT(result);
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_TRUE==first, "first should be true");
|
||||
NS_ASSERTION(PR_TRUE==any, "any should be true");
|
||||
NS_ASSERTION(PR_TRUE==all, "all should be true");
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
// remove the bold we just set
|
||||
printf("set the whole first text node to not bold\n");
|
||||
result = mTextEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
|
||||
TEST_RESULT(result);
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_FALSE==first, "first should be false");
|
||||
NS_ASSERTION(PR_FALSE==any, "any should be false");
|
||||
NS_ASSERTION(PR_FALSE==all, "all should be false");
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
// set all but the first and last character to bold
|
||||
printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
|
||||
selection->Collapse(textNode, 1);
|
||||
selection->Extend(textNode, length-1);
|
||||
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
|
||||
TEST_RESULT(result);
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_TRUE==first, "first should be true");
|
||||
NS_ASSERTION(PR_TRUE==any, "any should be true");
|
||||
NS_ASSERTION(PR_TRUE==all, "all should be true");
|
||||
mEditor->DebugDumpContent();
|
||||
// make all that same text italic
|
||||
result = mTextEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
|
||||
TEST_RESULT(result);
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_TRUE==first, "first should be true");
|
||||
NS_ASSERTION(PR_TRUE==any, "any should be true");
|
||||
NS_ASSERTION(PR_TRUE==all, "all should be true");
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_TRUE==first, "first should be true");
|
||||
NS_ASSERTION(PR_TRUE==any, "any should be true");
|
||||
NS_ASSERTION(PR_TRUE==all, "all should be true");
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
// make all the text underlined, except for the first 2 and last 2 characters
|
||||
result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(nodeList.get());
|
||||
nodeList->GetLength(&count);
|
||||
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
|
||||
result = nodeList->Item(count-2, getter_AddRefs(textNode));
|
||||
TEST_RESULT(result);
|
||||
TEST_POINTER(textNode.get());
|
||||
textData = do_QueryInterface(textNode);
|
||||
textData->GetLength(&length);
|
||||
NS_ASSERTION(length==249, "wrong text node");
|
||||
selection->Collapse(textNode, 1);
|
||||
selection->Extend(textNode, length-2);
|
||||
result = mTextEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
|
||||
TEST_RESULT(result);
|
||||
result = mTextEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
|
||||
TEST_RESULT(result);
|
||||
NS_ASSERTION(PR_TRUE==first, "first should be true");
|
||||
NS_ASSERTION(PR_TRUE==any, "any should be true");
|
||||
NS_ASSERTION(PR_TRUE==all, "all should be true");
|
||||
mEditor->DebugDumpContent();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
53
mozilla/editor/base/TextEditorTest.h
Normal file
53
mozilla/editor/base/TextEditorTest.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __TextEditorTest_h__
|
||||
#define __TextEditorTest_h__
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
class TextEditorTest
|
||||
{
|
||||
public:
|
||||
|
||||
void Run(nsIEditor *aEditor, PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
|
||||
TextEditorTest();
|
||||
~TextEditorTest();
|
||||
|
||||
protected:
|
||||
|
||||
/** create an empty document */
|
||||
nsresult InitDoc();
|
||||
|
||||
nsresult RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
|
||||
|
||||
nsresult TestInsertBreak();
|
||||
|
||||
nsresult TestTextProperties();
|
||||
|
||||
nsCOMPtr<nsIHighLevelHTMLEditor> mTextEditor;
|
||||
nsCOMPtr<nsIEditor> mEditor;
|
||||
};
|
||||
|
||||
#endif /* NS_DEBUG */
|
||||
|
||||
#endif
|
||||
94
mozilla/editor/base/TransactionFactory.cpp
Normal file
94
mozilla/editor/base/TransactionFactory.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "TransactionFactory.h"
|
||||
// transactions this factory knows how to build
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "PlaceholderTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "CreateElementTxn.h"
|
||||
#include "InsertElementTxn.h"
|
||||
#include "nsInsertHTMLTxn.h"
|
||||
#include "DeleteElementTxn.h"
|
||||
#include "DeleteRangeTxn.h"
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
#include "nsStyleSheetTxns.h"
|
||||
#include "IMETextTxn.h"
|
||||
#include "IMECommitTxn.h"
|
||||
|
||||
TransactionFactory::TransactionFactory()
|
||||
{
|
||||
}
|
||||
|
||||
TransactionFactory::~TransactionFactory()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
TransactionFactory::GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
*aResult = nsnull;
|
||||
if (aTxnType.Equals(InsertTextTxn::GetCID()))
|
||||
*aResult = new InsertTextTxn();
|
||||
else if (aTxnType.Equals(DeleteTextTxn::GetCID()))
|
||||
*aResult = new DeleteTextTxn();
|
||||
else if (aTxnType.Equals(CreateElementTxn::GetCID()))
|
||||
*aResult = new CreateElementTxn();
|
||||
else if (aTxnType.Equals(InsertElementTxn::GetCID()))
|
||||
*aResult = new InsertElementTxn();
|
||||
else if (aTxnType.Equals(nsInsertHTMLTxn::GetCID()))
|
||||
*aResult = new nsInsertHTMLTxn();
|
||||
else if (aTxnType.Equals(DeleteElementTxn::GetCID()))
|
||||
*aResult = new DeleteElementTxn();
|
||||
else if (aTxnType.Equals(DeleteRangeTxn::GetCID()))
|
||||
*aResult = new DeleteRangeTxn();
|
||||
else if (aTxnType.Equals(ChangeAttributeTxn::GetCID()))
|
||||
*aResult = new ChangeAttributeTxn();
|
||||
else if (aTxnType.Equals(SplitElementTxn::GetCID()))
|
||||
*aResult = new SplitElementTxn();
|
||||
else if (aTxnType.Equals(JoinElementTxn::GetCID()))
|
||||
*aResult = new JoinElementTxn();
|
||||
else if (aTxnType.Equals(EditAggregateTxn::GetCID()))
|
||||
*aResult = new EditAggregateTxn();
|
||||
else if (aTxnType.Equals(IMETextTxn::GetCID()))
|
||||
*aResult = new IMETextTxn();
|
||||
else if (aTxnType.Equals(IMECommitTxn::GetCID()))
|
||||
*aResult = new IMECommitTxn();
|
||||
else if (aTxnType.Equals(AddStyleSheetTxn::GetCID()))
|
||||
*aResult = new AddStyleSheetTxn();
|
||||
else if (aTxnType.Equals(RemoveStyleSheetTxn::GetCID()))
|
||||
*aResult = new RemoveStyleSheetTxn();
|
||||
else if (aTxnType.Equals(PlaceholderTxn::GetCID()))
|
||||
*aResult = new PlaceholderTxn();
|
||||
else
|
||||
result = NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (NS_SUCCEEDED(result) && nsnull==*aResult)
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_SUCCEEDED(result))
|
||||
NS_ADDREF(*aResult);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
45
mozilla/editor/base/TransactionFactory.h
Normal file
45
mozilla/editor/base/TransactionFactory.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef TransactionFactory_h__
|
||||
#define TransactionFactory_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class EditTxn;
|
||||
|
||||
/**
|
||||
* This class instantiates and optionally recycles edit transactions
|
||||
* A recycler would be a separate static object, since this class does not get instantiated
|
||||
*/
|
||||
class TransactionFactory
|
||||
{
|
||||
protected:
|
||||
TransactionFactory();
|
||||
virtual ~TransactionFactory();
|
||||
|
||||
public:
|
||||
/** return a transaction object of aTxnType, refcounted
|
||||
* @return NS_ERROR_NO_INTERFACE if aTxnType is unknown,
|
||||
* NS_ERROR_OUT_OF_MEMORY if the allocations fails.
|
||||
*/
|
||||
static nsresult GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
54
mozilla/editor/base/TypeInState.cpp
Normal file
54
mozilla/editor/base/TypeInState.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "TypeInState.h"
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(TypeInState)
|
||||
NS_IMPL_RELEASE(TypeInState)
|
||||
|
||||
NS_IMETHODIMP
|
||||
TypeInState::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMSelectionListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIDOMSelectionListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
TypeInState::~TypeInState()
|
||||
{
|
||||
};
|
||||
|
||||
NS_IMETHODIMP TypeInState::NotifySelectionChanged()
|
||||
{
|
||||
Reset();
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
232
mozilla/editor/base/TypeInState.h
Normal file
232
mozilla/editor/base/TypeInState.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef TypeInState_h__
|
||||
#define TypeInState_h__
|
||||
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#include "nsIEditProperty.h"
|
||||
|
||||
class TypeInState : public nsIDOMSelectionListener
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
TypeInState();
|
||||
void Reset();
|
||||
virtual ~TypeInState();
|
||||
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
void GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum);
|
||||
|
||||
void SetProp(PRUint32 aProp, PRBool aSet);
|
||||
|
||||
void SetPropValue(PRUint32 aProp, const nsString &aValue);
|
||||
|
||||
PRBool IsSet(PRUint32 aStyle);
|
||||
PRBool IsAnySet();
|
||||
void UnSet(PRUint32 aStyle);
|
||||
|
||||
void SetBold(PRBool aIsSet);
|
||||
PRBool GetBold();
|
||||
|
||||
void SetItalic(PRBool aIsSet);
|
||||
PRBool GetItalic();
|
||||
|
||||
void SetUnderline(PRBool aIsSet);
|
||||
PRBool GetUnderline();
|
||||
|
||||
void SetFontFace(const nsString &aFace);
|
||||
void GetFontFace(nsString &aFace);
|
||||
|
||||
void SetFontColor(const nsString &aColor);
|
||||
void GetFontColor(nsString &aColor);
|
||||
|
||||
void SetFontSize(const nsString &aSize);
|
||||
void GetFontSize(nsString &aSize);
|
||||
|
||||
protected:
|
||||
PRBool mBold;
|
||||
PRBool mItalic;
|
||||
PRBool mUnderline;
|
||||
nsString mFontFace;
|
||||
nsString mFontColor;
|
||||
nsString mFontSize;
|
||||
PRUint32 mIsSet;
|
||||
};
|
||||
|
||||
#define NS_TYPEINSTATE_UNKNOWN 0x00000000
|
||||
#define NS_TYPEINSTATE_BOLD 0x00000001
|
||||
#define NS_TYPEINSTATE_ITALIC 0x00000002
|
||||
#define NS_TYPEINSTATE_UNDERLINE 0x00000004
|
||||
#define NS_TYPEINSTATE_FONTFACE 0x00000008
|
||||
#define NS_TYPEINSTATE_FONTCOLOR 0x00000010
|
||||
#define NS_TYPEINSTATE_FONTSIZE 0x00000020
|
||||
|
||||
/* ----- inline method definitions ----- */
|
||||
inline
|
||||
void TypeInState::Reset()
|
||||
{
|
||||
mBold = PR_FALSE;
|
||||
mItalic = PR_FALSE;
|
||||
mUnderline = PR_FALSE;
|
||||
mIsSet = 0;
|
||||
};
|
||||
|
||||
inline
|
||||
TypeInState::TypeInState()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
Reset();
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum)
|
||||
{
|
||||
aEnum = NS_TYPEINSTATE_UNKNOWN;
|
||||
if (nsIEditProperty::b==aPropName) { aEnum = NS_TYPEINSTATE_BOLD; }
|
||||
else if (nsIEditProperty::i==aPropName) { aEnum = NS_TYPEINSTATE_ITALIC; }
|
||||
else if (nsIEditProperty::u==aPropName) { aEnum = NS_TYPEINSTATE_UNDERLINE; }
|
||||
else if (nsIEditProperty::face==aPropName) { aEnum = NS_TYPEINSTATE_FONTFACE; }
|
||||
else if (nsIEditProperty::color==aPropName) { aEnum = NS_TYPEINSTATE_FONTCOLOR; }
|
||||
else if (nsIEditProperty::size==aPropName) { aEnum = NS_TYPEINSTATE_FONTSIZE; }
|
||||
}
|
||||
|
||||
inline
|
||||
PRBool TypeInState::IsSet(PRUint32 aStyle)
|
||||
{
|
||||
if ((PRBool)(mIsSet & aStyle))
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::UnSet(PRUint32 aStyle)
|
||||
{
|
||||
mIsSet &= ~aStyle;
|
||||
};
|
||||
|
||||
inline
|
||||
PRBool TypeInState::IsAnySet()
|
||||
{
|
||||
return (PRBool)(0!=mIsSet);
|
||||
}
|
||||
|
||||
inline
|
||||
void TypeInState::SetBold(PRBool aIsSet)
|
||||
{
|
||||
mBold = aIsSet;
|
||||
mIsSet |= NS_TYPEINSTATE_BOLD;
|
||||
};
|
||||
|
||||
inline
|
||||
PRBool TypeInState::GetBold()
|
||||
{ return mBold;};
|
||||
|
||||
inline
|
||||
void TypeInState::SetItalic(PRBool aIsSet)
|
||||
{
|
||||
mItalic = aIsSet;
|
||||
mIsSet |= NS_TYPEINSTATE_ITALIC;
|
||||
};
|
||||
|
||||
inline
|
||||
PRBool TypeInState::GetItalic()
|
||||
{ return mItalic; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetUnderline(PRBool aIsSet)
|
||||
{
|
||||
mUnderline = aIsSet;
|
||||
mIsSet |= NS_TYPEINSTATE_UNDERLINE;
|
||||
};
|
||||
|
||||
inline
|
||||
PRBool TypeInState::GetUnderline()
|
||||
{ return mUnderline; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontFace(const nsString &aFace)
|
||||
{
|
||||
mFontFace = aFace;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTFACE;
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetFontFace(nsString &aFace)
|
||||
{ aFace = mFontFace; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontColor(const nsString &aColor)
|
||||
{
|
||||
mFontColor = aColor;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTCOLOR;
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetFontColor(nsString &aColor)
|
||||
{ aColor = mFontColor; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontSize(const nsString &aSize)
|
||||
{
|
||||
mFontSize = aSize;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTSIZE;
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetFontSize(nsString &aSize)
|
||||
{ aSize = mFontSize; };
|
||||
|
||||
inline void TypeInState::SetProp(PRUint32 aProp, PRBool aSet)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_BOLD:
|
||||
SetBold(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_ITALIC:
|
||||
SetItalic(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_UNDERLINE:
|
||||
SetUnderline(aSet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TypeInState::SetPropValue(PRUint32 aProp, const nsString &aValue)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_FONTFACE:
|
||||
SetFontFace(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTCOLOR:
|
||||
SetFontColor(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTSIZE:
|
||||
SetFontSize(aValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TypeInState_h__
|
||||
|
||||
150
mozilla/editor/base/makefile.win
Normal file
150
mozilla/editor/base/makefile.win
Normal file
@@ -0,0 +1,150 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LIBRARY_NAME=ender
|
||||
|
||||
CPPSRCS = \
|
||||
nsInsertHTMLTxn.cpp \
|
||||
nsEditor.cpp \
|
||||
nsEditorUtils.cpp \
|
||||
nsEditorRegistration.cpp \
|
||||
nsTextEditRules.cpp \
|
||||
nsHTMLEditRules.cpp \
|
||||
TextEditorTest.cpp \
|
||||
nsEditorEventListeners.cpp \
|
||||
nsEditProperty.cpp \
|
||||
nsEditorFactory.cpp \
|
||||
EditTxn.cpp \
|
||||
EditAggregateTxn.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
InsertTextTxn.cpp \
|
||||
DeleteTextTxn.cpp \
|
||||
PlaceholderTxn.cpp \
|
||||
CreateElementTxn.cpp \
|
||||
InsertElementTxn.cpp \
|
||||
DeleteElementTxn.cpp \
|
||||
DeleteRangeTxn.cpp \
|
||||
SplitElementTxn.cpp \
|
||||
JoinElementTxn.cpp \
|
||||
nsStyleSheetTxns.cpp \
|
||||
TransactionFactory.cpp \
|
||||
TypeInState.cpp \
|
||||
nsHTMLEditor.cpp \
|
||||
EditTable.cpp \
|
||||
nsInternetCiter.cpp \
|
||||
nsAOLCiter.cpp \
|
||||
nsInterfaceState.cpp \
|
||||
nsEditorShell.cpp \
|
||||
nsEditorShellFactory.cpp \
|
||||
IMETextTxn.cpp \
|
||||
IMECommitTxn.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsInsertHTMLTxn.obj \
|
||||
.\$(OBJDIR)\nsEditor.obj \
|
||||
.\$(OBJDIR)\nsEditorUtils.obj \
|
||||
.\$(OBJDIR)\nsEditorRegistration.obj \
|
||||
.\$(OBJDIR)\nsTextEditRules.obj \
|
||||
.\$(OBJDIR)\TextEditorTest.obj \
|
||||
.\$(OBJDIR)\nsHTMLEditRules.obj \
|
||||
.\$(OBJDIR)\nsEditorEventListeners.obj \
|
||||
.\$(OBJDIR)\nsEditProperty.obj \
|
||||
.\$(OBJDIR)\nsEditorFactory.obj \
|
||||
.\$(OBJDIR)\EditTxn.obj \
|
||||
.\$(OBJDIR)\EditAggregateTxn.obj \
|
||||
.\$(OBJDIR)\ChangeAttributeTxn.obj \
|
||||
.\$(OBJDIR)\InsertTextTxn.obj \
|
||||
.\$(OBJDIR)\DeleteTextTxn.obj \
|
||||
.\$(OBJDIR)\PlaceholderTxn.obj \
|
||||
.\$(OBJDIR)\CreateElementTxn.obj \
|
||||
.\$(OBJDIR)\InsertElementTxn.obj \
|
||||
.\$(OBJDIR)\DeleteElementTxn.obj \
|
||||
.\$(OBJDIR)\DeleteRangeTxn.obj \
|
||||
.\$(OBJDIR)\SplitElementTxn.obj \
|
||||
.\$(OBJDIR)\JoinElementTxn.obj \
|
||||
.\$(OBJDIR)\nsStyleSheetTxns.obj \
|
||||
.\$(OBJDIR)\TransactionFactory.obj \
|
||||
.\$(OBJDIR)\TypeInState.obj \
|
||||
.\$(OBJDIR)\nsHTMLEditor.obj \
|
||||
.\$(OBJDIR)\EditTable.obj \
|
||||
.\$(OBJDIR)\nsInternetCiter.obj \
|
||||
.\$(OBJDIR)\nsAOLCiter.obj \
|
||||
.\$(OBJDIR)\nsInterfaceState.obj \
|
||||
.\$(OBJDIR)\nsEditorShell.obj \
|
||||
.\$(OBJDIR)\nsEditorShellFactory.obj \
|
||||
.\$(OBJDIR)\nsJSEditorLog.obj \
|
||||
.\$(OBJDIR)\nsJSTxnLog.obj \
|
||||
.\$(OBJDIR)\IMETextTxn.obj \
|
||||
.\$(OBJDIR)\IMECommitTxn.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
MODULE=editor
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = ender
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
!if defined(ENABLE_JS_EDITOR_LOG)
|
||||
CPPSRCS += \
|
||||
nsJSEditorLog.cpp \
|
||||
nsJSTxnLog.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS += \
|
||||
.\$(OBJDIR)\nsJSEditorLog.obj \
|
||||
.\$(OBJDIR)\nsJSTxnLog.obj \
|
||||
$(NULL)
|
||||
|
||||
DEFINES = -DENABLE_JS_EDITOR_LOG $(DEFINES)
|
||||
!endif
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
# These are the libraries we need to link with to create the dll
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\raptorhtmlpars.lib \
|
||||
$(DIST)\lib\raptorwidget_s.lib \
|
||||
!ifdef NECKO
|
||||
$(DIST)\lib\neckoutil_s.lib \
|
||||
!else
|
||||
$(DIST)\lib\netlib.lib \
|
||||
!endif
|
||||
$(LIBNSPR)
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\components\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||
82
mozilla/editor/base/nsAOLCiter.cpp
Normal file
82
mozilla/editor/base/nsAOLCiter.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsAOLCiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
*/
|
||||
|
||||
nsAOLCiter::nsAOLCiter()
|
||||
{
|
||||
}
|
||||
|
||||
nsAOLCiter::~nsAOLCiter()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsAOLCiter)
|
||||
|
||||
NS_IMPL_RELEASE(nsAOLCiter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAOLCiter::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsICiter::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsICiter*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAOLCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
aOutString = "\n\n>> ";
|
||||
aOutString += aInString;
|
||||
|
||||
// See if the last char is a newline, and replace it if so
|
||||
PRUnichar newline ('\n');
|
||||
if (aOutString.Last() == newline)
|
||||
{
|
||||
aOutString.SetCharAt(' ',aOutString.Length());
|
||||
aOutString += "<<\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
aOutString += " <<\n";
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
mozilla/editor/base/nsAOLCiter.h
Normal file
41
mozilla/editor/base/nsAOLCiter.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsAOLCiter_h__
|
||||
#define nsAOLCiter_h__
|
||||
|
||||
#include "nsICiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
*/
|
||||
class nsAOLCiter : public nsICiter
|
||||
{
|
||||
public:
|
||||
nsAOLCiter();
|
||||
virtual ~nsAOLCiter();
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetCiteString(const nsString& aInString, nsString& aOutString);
|
||||
};
|
||||
|
||||
#endif //nsAOLCiter_h__
|
||||
|
||||
131
mozilla/editor/base/nsEditFactory.cpp
Normal file
131
mozilla/editor/base/nsEditFactory.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsEditFactory.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsEditorCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
|
||||
static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
GetEditFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
|
||||
// XXX Note static which never gets released, even on library unload.
|
||||
// XXX Was an nsCOMPtr but that caused a crash on exit,
|
||||
// XXX http://bugzilla.mozilla.org/show_bug.cgi?id=7938
|
||||
PR_EnterMonitor(GetEditorMonitor());
|
||||
|
||||
nsEditFactory *factory = new nsEditFactory(aClass);
|
||||
if (!factory)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
|
||||
if (!pNSIFactory)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(),
|
||||
(void **)aFactory);
|
||||
PR_ExitMonitor(GetEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports
|
||||
|
||||
NS_METHOD
|
||||
nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
NS_NOTREACHED("!nsEditor");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIFactory::GetIID()) ||
|
||||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsEditFactory)
|
||||
NS_IMPL_RELEASE(nsEditFactory)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_METHOD
|
||||
nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsISupports *obj = nsnull;
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aOuter && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
|
||||
|
||||
if (mCID.Equals(kEditorCID))
|
||||
obj = (nsISupports *)(nsIEditor*)new nsEditor();
|
||||
//more class ids to support. here
|
||||
|
||||
|
||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||
{
|
||||
delete obj;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsEditFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsEditFactory:
|
||||
|
||||
nsEditFactory::nsEditFactory(const nsCID &aClass)
|
||||
:mCID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsEditFactory::~nsEditFactory()
|
||||
{
|
||||
//nsComponentManager::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
67
mozilla/editor/base/nsEditFactory.h
Normal file
67
mozilla/editor/base/nsEditFactory.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsIEditFactory_h___
|
||||
#define nsIEditFactory_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
EditFactory that can make an editor
|
||||
*/
|
||||
|
||||
/**
|
||||
* This supplies the neccessary entrance to the edit module. it will return any
|
||||
* instantiations that we need.
|
||||
*/
|
||||
class nsEditFactory;
|
||||
|
||||
nsresult GetEditFactory(nsIFactory **aFactory, const nsCID & aClass);
|
||||
|
||||
class nsEditFactory : public nsIFactory {
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports and AggregatedQueryInterface:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHOD
|
||||
CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD
|
||||
LockFactory(PRBool aLock);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsEditFactory:
|
||||
|
||||
virtual ~nsEditFactory(void);
|
||||
private:
|
||||
nsEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
|
||||
|
||||
/** getEditFactory
|
||||
* creates an edit factory other CSID supported friend functions here.
|
||||
*/
|
||||
friend nsresult GetEditFactory(nsIFactory **, const nsCID & );
|
||||
const nsCID &mCID;
|
||||
};
|
||||
|
||||
#endif //nsIEditFactory_h___
|
||||
326
mozilla/editor/base/nsEditProperty.cpp
Normal file
326
mozilla/editor/base/nsEditProperty.cpp
Normal file
@@ -0,0 +1,326 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsEditProperty.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// singleton instance
|
||||
static nsEditProperty *gInstance;
|
||||
|
||||
NS_IMPL_ADDREF(nsEditProperty)
|
||||
|
||||
NS_IMPL_RELEASE(nsEditProperty)
|
||||
|
||||
|
||||
// XXX: remove when html atoms are exported from layout
|
||||
// inline tags
|
||||
nsIAtom * nsIEditProperty::b;
|
||||
nsIAtom * nsIEditProperty::big;
|
||||
nsIAtom * nsIEditProperty::i;
|
||||
nsIAtom * nsIEditProperty::small;
|
||||
nsIAtom * nsIEditProperty::strike;
|
||||
nsIAtom * nsIEditProperty::sub;
|
||||
nsIAtom * nsIEditProperty::sup;
|
||||
nsIAtom * nsIEditProperty::tt;
|
||||
nsIAtom * nsIEditProperty::u;
|
||||
nsIAtom * nsIEditProperty::em;
|
||||
nsIAtom * nsIEditProperty::strong;
|
||||
nsIAtom * nsIEditProperty::dfn;
|
||||
nsIAtom * nsIEditProperty::code;
|
||||
nsIAtom * nsIEditProperty::samp;
|
||||
nsIAtom * nsIEditProperty::kbd;
|
||||
nsIAtom * nsIEditProperty::var;
|
||||
nsIAtom * nsIEditProperty::cite;
|
||||
nsIAtom * nsIEditProperty::abbr;
|
||||
nsIAtom * nsIEditProperty::acronym;
|
||||
nsIAtom * nsIEditProperty::font;
|
||||
nsIAtom * nsIEditProperty::a;
|
||||
nsIAtom * nsIEditProperty::img;
|
||||
nsIAtom * nsIEditProperty::object;
|
||||
nsIAtom * nsIEditProperty::br;
|
||||
nsIAtom * nsIEditProperty::script;
|
||||
nsIAtom * nsIEditProperty::map;
|
||||
nsIAtom * nsIEditProperty::q;
|
||||
nsIAtom * nsIEditProperty::span;
|
||||
nsIAtom * nsIEditProperty::bdo;
|
||||
nsIAtom * nsIEditProperty::input;
|
||||
nsIAtom * nsIEditProperty::select;
|
||||
nsIAtom * nsIEditProperty::textarea;
|
||||
nsIAtom * nsIEditProperty::label;
|
||||
nsIAtom * nsIEditProperty::button;
|
||||
nsIAtom * nsIEditProperty::p;
|
||||
nsIAtom * nsIEditProperty::div;
|
||||
nsIAtom * nsIEditProperty::blockquote;
|
||||
nsIAtom * nsIEditProperty::h1;
|
||||
nsIAtom * nsIEditProperty::h2;
|
||||
nsIAtom * nsIEditProperty::h3;
|
||||
nsIAtom * nsIEditProperty::h4;
|
||||
nsIAtom * nsIEditProperty::h5;
|
||||
nsIAtom * nsIEditProperty::h6;
|
||||
nsIAtom * nsIEditProperty::ul;
|
||||
nsIAtom * nsIEditProperty::ol;
|
||||
nsIAtom * nsIEditProperty::dl;
|
||||
nsIAtom * nsIEditProperty::pre;
|
||||
nsIAtom * nsIEditProperty::noscript;
|
||||
nsIAtom * nsIEditProperty::form;
|
||||
nsIAtom * nsIEditProperty::hr;
|
||||
nsIAtom * nsIEditProperty::table;
|
||||
nsIAtom * nsIEditProperty::fieldset;
|
||||
nsIAtom * nsIEditProperty::address;
|
||||
nsIAtom * nsIEditProperty::body;
|
||||
nsIAtom * nsIEditProperty::tr;
|
||||
nsIAtom * nsIEditProperty::td;
|
||||
nsIAtom * nsIEditProperty::th;
|
||||
nsIAtom * nsIEditProperty::caption;
|
||||
nsIAtom * nsIEditProperty::col;
|
||||
nsIAtom * nsIEditProperty::colgroup;
|
||||
nsIAtom * nsIEditProperty::thead;
|
||||
nsIAtom * nsIEditProperty::tfoot;
|
||||
nsIAtom * nsIEditProperty::li;
|
||||
nsIAtom * nsIEditProperty::dt;
|
||||
nsIAtom * nsIEditProperty::dd;
|
||||
nsIAtom * nsIEditProperty::legend;
|
||||
nsIAtom * nsIEditProperty::color;
|
||||
nsIAtom * nsIEditProperty::face;
|
||||
nsIAtom * nsIEditProperty::size;
|
||||
|
||||
// special
|
||||
nsString * nsIEditProperty::allProperties;
|
||||
|
||||
/* From the HTML 4.0 DTD,
|
||||
|
||||
INLINE:
|
||||
<!-- %inline; covers inline or "text-level" elements -->
|
||||
<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">
|
||||
<!ENTITY % fontstyle "TT | I | B | BIG | SMALL">
|
||||
<!ENTITY % phrase "EM | STRONG | DFN | CODE |
|
||||
SAMP | KBD | VAR | CITE | ABBR | ACRONYM" >
|
||||
<!ENTITY % special
|
||||
"A | IMG | OBJECT | BR | SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO">
|
||||
<!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">
|
||||
|
||||
BLOCK:
|
||||
<!ENTITY % block
|
||||
"P | %heading (h1-h6); | %list (UL | OL); | %preformatted (PRE); | DL | DIV | NOSCRIPT |
|
||||
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
|
||||
|
||||
But what about BODY, TR, TD, TH, CAPTION, COL, COLGROUP, THEAD, TFOOT, LI, DT, DD, LEGEND, etc.?
|
||||
|
||||
|
||||
*/
|
||||
nsEditProperty::nsEditProperty()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// inline tags
|
||||
nsIEditProperty::b = NS_NewAtom("b");
|
||||
nsIEditProperty::big = NS_NewAtom("big");
|
||||
nsIEditProperty::i = NS_NewAtom("i");
|
||||
nsIEditProperty::small = NS_NewAtom("small");
|
||||
nsIEditProperty::strike = NS_NewAtom("strike");
|
||||
nsIEditProperty::sub = NS_NewAtom("sub");
|
||||
nsIEditProperty::sup = NS_NewAtom("sup");
|
||||
nsIEditProperty::tt = NS_NewAtom("tt");
|
||||
nsIEditProperty::u = NS_NewAtom("u");
|
||||
nsIEditProperty::em = NS_NewAtom("em");
|
||||
nsIEditProperty::strong = NS_NewAtom("strong");
|
||||
nsIEditProperty::dfn = NS_NewAtom("dfn");
|
||||
nsIEditProperty::code = NS_NewAtom("code");
|
||||
nsIEditProperty::samp = NS_NewAtom("samp");
|
||||
nsIEditProperty::kbd = NS_NewAtom("kbd");
|
||||
nsIEditProperty::var = NS_NewAtom("var");
|
||||
nsIEditProperty::cite = NS_NewAtom("cite");
|
||||
nsIEditProperty::abbr = NS_NewAtom("abbr");
|
||||
nsIEditProperty::acronym = NS_NewAtom("acronym");
|
||||
nsIEditProperty::font = NS_NewAtom("font");
|
||||
nsIEditProperty::a = NS_NewAtom("a");
|
||||
nsIEditProperty::img = NS_NewAtom("img");
|
||||
nsIEditProperty::object = NS_NewAtom("object");
|
||||
nsIEditProperty::br = NS_NewAtom("br");
|
||||
nsIEditProperty::script = NS_NewAtom("script");
|
||||
nsIEditProperty::map = NS_NewAtom("map");
|
||||
nsIEditProperty::q = NS_NewAtom("q");
|
||||
nsIEditProperty::span = NS_NewAtom("span");
|
||||
nsIEditProperty::bdo = NS_NewAtom("bdo");
|
||||
nsIEditProperty::input = NS_NewAtom("input");
|
||||
nsIEditProperty::select = NS_NewAtom("select");
|
||||
nsIEditProperty::textarea = NS_NewAtom("textarea");
|
||||
nsIEditProperty::label = NS_NewAtom("label");
|
||||
nsIEditProperty::button = NS_NewAtom("button");
|
||||
// block tags
|
||||
nsIEditProperty::p = NS_NewAtom("p");
|
||||
nsIEditProperty::div = NS_NewAtom("div");
|
||||
nsIEditProperty::blockquote = NS_NewAtom("blockquote");
|
||||
nsIEditProperty::h1 = NS_NewAtom("h1");
|
||||
nsIEditProperty::h2 = NS_NewAtom("h2");
|
||||
nsIEditProperty::h3 = NS_NewAtom("h3");
|
||||
nsIEditProperty::h4 = NS_NewAtom("h4");
|
||||
nsIEditProperty::h5 = NS_NewAtom("h5");
|
||||
nsIEditProperty::h6 = NS_NewAtom("h6");
|
||||
nsIEditProperty::ul = NS_NewAtom("ul");
|
||||
nsIEditProperty::ol = NS_NewAtom("ol");
|
||||
nsIEditProperty::dl = NS_NewAtom("dl");
|
||||
nsIEditProperty::pre = NS_NewAtom("pre");
|
||||
nsIEditProperty::noscript = NS_NewAtom("noscript");
|
||||
nsIEditProperty::form = NS_NewAtom("form");
|
||||
nsIEditProperty::hr = NS_NewAtom("hr");
|
||||
nsIEditProperty::table = NS_NewAtom("table");
|
||||
nsIEditProperty::fieldset = NS_NewAtom("fieldset");
|
||||
nsIEditProperty::address = NS_NewAtom("address");
|
||||
// Unclear from
|
||||
// DTD, block?
|
||||
nsIEditProperty::body = NS_NewAtom("body");
|
||||
nsIEditProperty::tr = NS_NewAtom("tr");
|
||||
nsIEditProperty::td = NS_NewAtom("td");
|
||||
nsIEditProperty::th = NS_NewAtom("th");
|
||||
nsIEditProperty::caption = NS_NewAtom("caption");
|
||||
nsIEditProperty::col = NS_NewAtom("col");
|
||||
nsIEditProperty::colgroup = NS_NewAtom("colgroup");
|
||||
nsIEditProperty::thead = NS_NewAtom("thead");
|
||||
nsIEditProperty::tfoot = NS_NewAtom("tfoot");
|
||||
nsIEditProperty::li = NS_NewAtom("li");
|
||||
nsIEditProperty::dt = NS_NewAtom("dt");
|
||||
nsIEditProperty::dd = NS_NewAtom("dd");
|
||||
nsIEditProperty::legend = NS_NewAtom("legend");
|
||||
// inline
|
||||
// properties
|
||||
nsIEditProperty::color = NS_NewAtom("color");
|
||||
nsIEditProperty::face = NS_NewAtom("face");
|
||||
nsIEditProperty::size = NS_NewAtom("size");
|
||||
|
||||
|
||||
// special
|
||||
nsIEditProperty::allProperties = new nsString("moz_allproperties");
|
||||
}
|
||||
|
||||
nsEditProperty::~nsEditProperty()
|
||||
{
|
||||
NS_IF_RELEASE(nsIEditProperty::b);
|
||||
NS_IF_RELEASE(nsIEditProperty::big);
|
||||
NS_IF_RELEASE(nsIEditProperty::i);
|
||||
NS_IF_RELEASE(nsIEditProperty::small);
|
||||
NS_IF_RELEASE(nsIEditProperty::strike);
|
||||
NS_IF_RELEASE(nsIEditProperty::sub);
|
||||
NS_IF_RELEASE(nsIEditProperty::sup);
|
||||
NS_IF_RELEASE(nsIEditProperty::tt);
|
||||
NS_IF_RELEASE(nsIEditProperty::u);
|
||||
NS_IF_RELEASE(nsIEditProperty::em);
|
||||
NS_IF_RELEASE(nsIEditProperty::strong);
|
||||
NS_IF_RELEASE(nsIEditProperty::dfn);
|
||||
NS_IF_RELEASE(nsIEditProperty::code);
|
||||
NS_IF_RELEASE(nsIEditProperty::samp);
|
||||
NS_IF_RELEASE(nsIEditProperty::kbd);
|
||||
NS_IF_RELEASE(nsIEditProperty::var);
|
||||
NS_IF_RELEASE(nsIEditProperty::cite);
|
||||
NS_IF_RELEASE(nsIEditProperty::abbr);
|
||||
NS_IF_RELEASE(nsIEditProperty::acronym);
|
||||
NS_IF_RELEASE(nsIEditProperty::font);
|
||||
NS_IF_RELEASE(nsIEditProperty::a);
|
||||
NS_IF_RELEASE(nsIEditProperty::img);
|
||||
NS_IF_RELEASE(nsIEditProperty::object);
|
||||
NS_IF_RELEASE(nsIEditProperty::br);
|
||||
NS_IF_RELEASE(nsIEditProperty::script);
|
||||
NS_IF_RELEASE(nsIEditProperty::map);
|
||||
NS_IF_RELEASE(nsIEditProperty::q);
|
||||
NS_IF_RELEASE(nsIEditProperty::span);
|
||||
NS_IF_RELEASE(nsIEditProperty::bdo);
|
||||
NS_IF_RELEASE(nsIEditProperty::input);
|
||||
NS_IF_RELEASE(nsIEditProperty::select);
|
||||
NS_IF_RELEASE(nsIEditProperty::textarea);
|
||||
NS_IF_RELEASE(nsIEditProperty::label);
|
||||
NS_IF_RELEASE(nsIEditProperty::button);
|
||||
NS_IF_RELEASE(nsIEditProperty::p);
|
||||
NS_IF_RELEASE(nsIEditProperty::div);
|
||||
NS_IF_RELEASE(nsIEditProperty::blockquote);
|
||||
NS_IF_RELEASE(nsIEditProperty::h1);
|
||||
NS_IF_RELEASE(nsIEditProperty::h2);
|
||||
NS_IF_RELEASE(nsIEditProperty::h3);
|
||||
NS_IF_RELEASE(nsIEditProperty::h4);
|
||||
NS_IF_RELEASE(nsIEditProperty::h5);
|
||||
NS_IF_RELEASE(nsIEditProperty::h6);
|
||||
NS_IF_RELEASE(nsIEditProperty::ul);
|
||||
NS_IF_RELEASE(nsIEditProperty::ol);
|
||||
NS_IF_RELEASE(nsIEditProperty::dl);
|
||||
NS_IF_RELEASE(nsIEditProperty::pre);
|
||||
NS_IF_RELEASE(nsIEditProperty::noscript);
|
||||
NS_IF_RELEASE(nsIEditProperty::form);
|
||||
NS_IF_RELEASE(nsIEditProperty::hr);
|
||||
NS_IF_RELEASE(nsIEditProperty::table);
|
||||
NS_IF_RELEASE(nsIEditProperty::fieldset);
|
||||
NS_IF_RELEASE(nsIEditProperty::address);
|
||||
NS_IF_RELEASE(nsIEditProperty::body);
|
||||
NS_IF_RELEASE(nsIEditProperty::tr);
|
||||
NS_IF_RELEASE(nsIEditProperty::td);
|
||||
NS_IF_RELEASE(nsIEditProperty::th);
|
||||
NS_IF_RELEASE(nsIEditProperty::caption);
|
||||
NS_IF_RELEASE(nsIEditProperty::col);
|
||||
NS_IF_RELEASE(nsIEditProperty::colgroup);
|
||||
NS_IF_RELEASE(nsIEditProperty::thead);
|
||||
NS_IF_RELEASE(nsIEditProperty::tfoot);
|
||||
NS_IF_RELEASE(nsIEditProperty::li);
|
||||
NS_IF_RELEASE(nsIEditProperty::dt);
|
||||
NS_IF_RELEASE(nsIEditProperty::dd);
|
||||
NS_IF_RELEASE(nsIEditProperty::legend);
|
||||
NS_IF_RELEASE(nsIEditProperty::color);
|
||||
NS_IF_RELEASE(nsIEditProperty::face);
|
||||
NS_IF_RELEASE(nsIEditProperty::size);
|
||||
|
||||
// special
|
||||
if (nsIEditProperty::allProperties) {
|
||||
delete (nsIEditProperty::allProperties);
|
||||
nsIEditProperty::allProperties = nsnull;
|
||||
}
|
||||
gInstance = nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditProperty::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIEditProperty::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIEditProperty*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
/* Factory for edit property object */
|
||||
nsresult NS_NewEditProperty(nsIEditProperty **aResult)
|
||||
{
|
||||
if (aResult)
|
||||
{
|
||||
if (!gInstance)
|
||||
{
|
||||
gInstance = new nsEditProperty();
|
||||
if (!gInstance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
*aResult = gInstance;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
45
mozilla/editor/base/nsEditProperty.h
Normal file
45
mozilla/editor/base/nsEditProperty.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsEditProperty_h__
|
||||
#define __nsEditProperty_h__
|
||||
|
||||
#include "nsIEditProperty.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
/** simple class for describing a single property as it relates to a range of content.
|
||||
* not ref counted.
|
||||
*
|
||||
*/
|
||||
class nsEditProperty : public nsIEditProperty
|
||||
{
|
||||
public:
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
protected:
|
||||
nsEditProperty ();
|
||||
virtual ~nsEditProperty();
|
||||
|
||||
friend nsresult NS_NewEditProperty(nsIEditProperty **aResult);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
55
mozilla/editor/base/nsEditRules.h
Normal file
55
mozilla/editor/base/nsEditRules.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsEditRules_h__
|
||||
#define nsEditRules_h__
|
||||
|
||||
class nsHTMLEditor;
|
||||
class nsIDOMSelection;
|
||||
|
||||
/***************************************************************************
|
||||
* base for an object to encapsulate any additional info needed to be passed
|
||||
* to rules system by the editor
|
||||
*/
|
||||
class nsRulesInfo
|
||||
{
|
||||
public:
|
||||
|
||||
nsRulesInfo(int aAction) : action(aAction) {}
|
||||
virtual ~nsRulesInfo() {}
|
||||
|
||||
int action;
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* Interface of editing rules.
|
||||
*
|
||||
*/
|
||||
class nsEditRules
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Init(nsHTMLEditor *aEditor)=0;
|
||||
NS_IMETHOD WillDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel)=0;
|
||||
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags)=0;
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
|
||||
|
||||
};
|
||||
|
||||
#endif //nsEditRules_h__
|
||||
|
||||
4259
mozilla/editor/base/nsEditor.cpp
Normal file
4259
mozilla/editor/base/nsEditor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
633
mozilla/editor/base/nsEditor.h
Normal file
633
mozilla/editor/base/nsEditor.h
Normal file
@@ -0,0 +1,633 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __editor_h__
|
||||
#define __editor_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prmon.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIEditorIMESupport.h"
|
||||
#include "nsIEditorLogging.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMTextRangeList.h"
|
||||
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "TransactionFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIEditProperty.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsIDTD.h"
|
||||
|
||||
class nsIEditActionListener;
|
||||
class nsIDocumentStateListener;
|
||||
class nsIDOMCharacterData;
|
||||
class nsIDOMRange;
|
||||
class nsIPresShell;
|
||||
class nsIViewManager;
|
||||
class ChangeAttributeTxn;
|
||||
class CreateElementTxn;
|
||||
class InsertElementTxn;
|
||||
class DeleteElementTxn;
|
||||
class InsertTextTxn;
|
||||
class DeleteTextTxn;
|
||||
class SplitElementTxn;
|
||||
class JoinElementTxn;
|
||||
class EditAggregateTxn;
|
||||
class nsVoidArray;
|
||||
class nsISupportsArray;
|
||||
class nsIPref;
|
||||
class nsIStringBundleService;
|
||||
class nsIStringBundle;
|
||||
class nsILocale;
|
||||
class IMETextTxn;
|
||||
class AddStyleSheetTxn;
|
||||
class RemoveStyleSheetTxn;
|
||||
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
class nsJSEditorLog;
|
||||
class nsJSTxnLog;
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
//This is the monitor for the editor.
|
||||
PRMonitor *GetEditorMonitor();
|
||||
|
||||
|
||||
/** implementation of an editor object. it will be the controler/focal point
|
||||
* for the main editor services. i.e. the GUIManager, publishing, transaction
|
||||
* manager, event interfaces. the idea for the event interfaces is to have them
|
||||
* delegate the actual commands to the editor independent of the XPFE implementation.
|
||||
*/
|
||||
class nsEditor : public nsIEditor,
|
||||
public nsIEditorIMESupport,
|
||||
public nsIEditorLogging
|
||||
{
|
||||
public:
|
||||
|
||||
enum IterDirection
|
||||
{
|
||||
kIterForward,
|
||||
kIterBackward
|
||||
};
|
||||
|
||||
static const char* kMOZEditorBogusNodeAttr;
|
||||
static const char* kMOZEditorBogusNodeValue;
|
||||
|
||||
/** The default constructor. This should suffice. the setting of the interfaces is done
|
||||
* after the construction of the editor class.
|
||||
*/
|
||||
nsEditor();
|
||||
/** The default destructor. This should suffice. Should this be pure virtual
|
||||
* for someone to derive from the nsEditor later? I dont believe so.
|
||||
*/
|
||||
virtual ~nsEditor();
|
||||
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* ------------ nsIEditor methods -------------- */
|
||||
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags);
|
||||
NS_IMETHOD PostCreate();
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags) = 0;
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags) = 0;
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
|
||||
NS_IMETHOD GetPresShell(nsIPresShell **aPS);
|
||||
NS_IMETHOD GetSelection(nsIDOMSelection **aSelection);
|
||||
|
||||
NS_IMETHOD EnableUndo(PRBool aEnable);
|
||||
NS_IMETHOD Do(nsITransaction *aTxn);
|
||||
NS_IMETHOD Undo(PRUint32 aCount);
|
||||
NS_IMETHOD CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
NS_IMETHOD Redo(PRUint32 aCount);
|
||||
NS_IMETHOD CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
|
||||
NS_IMETHOD BeginTransaction();
|
||||
NS_IMETHOD EndTransaction();
|
||||
|
||||
// file handling
|
||||
NS_IMETHOD Save();
|
||||
NS_IMETHOD SaveAs(PRBool aSavingCopy);
|
||||
NS_IMETHOD GetDocumentModified(PRBool *outDocModified);
|
||||
|
||||
// these are pure virtual in this base class
|
||||
NS_IMETHOD Cut() = 0;
|
||||
NS_IMETHOD Copy() = 0;
|
||||
NS_IMETHOD Paste() = 0;
|
||||
|
||||
NS_IMETHOD SelectAll();
|
||||
|
||||
NS_IMETHOD BeginningOfDocument();
|
||||
NS_IMETHOD EndOfDocument();
|
||||
|
||||
|
||||
/* Node and element manipulation */
|
||||
NS_IMETHOD SetAttribute(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue);
|
||||
|
||||
NS_IMETHOD GetAttributeValue(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
nsString& aResultValue,
|
||||
PRBool& aResultIsSet);
|
||||
|
||||
NS_IMETHOD RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute);
|
||||
|
||||
NS_IMETHOD CreateNode(const nsString& aTag,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition,
|
||||
nsIDOMNode ** aNewNode);
|
||||
|
||||
NS_IMETHOD InsertNode(nsIDOMNode * aNode,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition);
|
||||
|
||||
NS_IMETHOD SplitNode(nsIDOMNode * aExistingRightNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMNode ** aNewLeftNode);
|
||||
|
||||
NS_IMETHOD JoinNodes(nsIDOMNode * aLeftNode,
|
||||
nsIDOMNode * aRightNode,
|
||||
nsIDOMNode * aParent);
|
||||
|
||||
NS_IMETHOD DeleteNode(nsIDOMNode * aChild);
|
||||
|
||||
|
||||
/* output */
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
/* Listeners */
|
||||
NS_IMETHOD AddEditActionListener(nsIEditActionListener *aListener);
|
||||
NS_IMETHOD RemoveEditActionListener(nsIEditActionListener *aListener);
|
||||
|
||||
NS_IMETHOD AddDocumentStateListener(nsIDocumentStateListener *aListener);
|
||||
NS_IMETHOD RemoveDocumentStateListener(nsIDocumentStateListener *aListener);
|
||||
|
||||
|
||||
NS_IMETHOD DumpContentTree();
|
||||
NS_IMETHOD DebugDumpContent() const;
|
||||
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
|
||||
|
||||
/* ------------ nsIEditorIMESupport methods -------------- */
|
||||
|
||||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRangeList);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
|
||||
/* ------------ nsIEditorLogging methods -------------- */
|
||||
|
||||
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
|
||||
NS_IMETHOD StopLogging();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
NS_IMETHOD InsertTextImpl(const nsString& aStringToInsert);
|
||||
NS_IMETHOD DeleteSelectionImpl(ESelectionCollapseDirection aAction);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// why not use the one in nsHTMLDocument?
|
||||
NS_IMETHOD GetBodyElement(nsIDOMElement **aElement);
|
||||
|
||||
//NOTE: Most callers are dealing with Nodes,
|
||||
// but these objects must supports nsIDOMElement
|
||||
NS_IMETHOD CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode);
|
||||
/*
|
||||
NS_IMETHOD SetProperties(nsVoidArray *aPropList);
|
||||
NS_IMETHOD GetProperties(nsVoidArray *aPropList);
|
||||
*/
|
||||
|
||||
/** create a transaction for setting aAttribute to aValue on aElement
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForSetAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
/** create a transaction for removing aAttribute on aElement
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
/** create a transaction for creating a new child node of aParent of type aTag.
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForCreateElement(const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aPosition,
|
||||
CreateElementTxn ** aTxn);
|
||||
|
||||
/** create a transaction for inserting aNode as a child of aParent.
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForInsertElement(nsIDOMNode * aNode,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aOffset,
|
||||
InsertElementTxn ** aTxn);
|
||||
|
||||
/** create a transaction for removing aElement from its parent.
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForDeleteElement(nsIDOMNode * aElement,
|
||||
DeleteElementTxn ** aTxn);
|
||||
|
||||
|
||||
/** Create an aggregate transaction for deleting current selection
|
||||
* Used by all methods that need to delete current selection,
|
||||
* then insert something new to replace it
|
||||
* @param nsString& aTxnName is the name of the aggregated transaction
|
||||
* @param EditTxn **aAggTxn is the return location of the aggregate TXN,
|
||||
* with the DeleteSelectionTxn as the first child ONLY
|
||||
* if there was a selection to delete.
|
||||
*/
|
||||
NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn);
|
||||
|
||||
|
||||
NS_IMETHOD CreateTxnForDeleteSelection(ESelectionCollapseDirection aAction,
|
||||
EditAggregateTxn ** aTxn);
|
||||
|
||||
NS_IMETHOD CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
||||
ESelectionCollapseDirection aAction,
|
||||
EditAggregateTxn *aTxn);
|
||||
|
||||
|
||||
/** create a transaction for inserting aStringToInsert into aTextNode
|
||||
* if aTextNode is null, the string is inserted at the current selection.
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForInsertText(const nsString & aStringToInsert,
|
||||
nsIDOMCharacterData *aTextNode,
|
||||
InsertTextTxn ** aTxn);
|
||||
|
||||
NS_IMETHOD CreateTxnForIMEText(const nsString & aStringToInsert,
|
||||
nsIDOMTextRangeList* aTextRangeList,
|
||||
IMETextTxn ** aTxn);
|
||||
|
||||
/** create a transaction for adding a style sheet
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForAddStyleSheet(nsICSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn);
|
||||
|
||||
/** create a transaction for removing a style sheet
|
||||
*/
|
||||
NS_IMETHOD CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn);
|
||||
|
||||
/** insert aStringToInsert as the first text in the document
|
||||
*/
|
||||
NS_IMETHOD DoInitialInsert(const nsString & aStringToInsert);
|
||||
|
||||
NS_IMETHOD DoInitialInputMethodInsert(const nsString& aStringToInsert,nsIDOMTextRangeList* aTextRangeList);
|
||||
|
||||
|
||||
NS_IMETHOD DeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
NS_IMETHOD CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength,
|
||||
DeleteTextTxn **aTxn);
|
||||
|
||||
NS_IMETHOD CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
PRUint32 aOffset,
|
||||
SplitElementTxn **aTxn);
|
||||
|
||||
NS_IMETHOD CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
|
||||
nsIDOMNode *aRightNode,
|
||||
JoinElementTxn **aTxn);
|
||||
|
||||
|
||||
NS_IMETHOD SetInputMethodText(const nsString& aStringToInsert, nsIDOMTextRangeList* aTextRangeList);
|
||||
|
||||
// called each time we modify the document. Increments the mod
|
||||
// count of the doc.
|
||||
NS_IMETHOD IncDocModCount(PRInt32 inNumMods);
|
||||
|
||||
// return the mod count of the doc we are editing. Zero means unchanged.
|
||||
NS_IMETHOD GetDocModCount(PRInt32 &outModCount);
|
||||
|
||||
// called ONLY when we need to override the doc's modification
|
||||
// state. This should already be handled by nsIDiskDocument.
|
||||
NS_IMETHOD ResetDocModCount();
|
||||
|
||||
// called after a transaction is done successfully
|
||||
NS_IMETHOD DoAfterDoTransaction(nsITransaction *aTxn);
|
||||
// called after a transaction is undone successfully
|
||||
NS_IMETHOD DoAfterUndoTransaction();
|
||||
// called after a transaction is redone successfully
|
||||
NS_IMETHOD DoAfterRedoTransaction();
|
||||
|
||||
// called after the document has been saved
|
||||
NS_IMETHOD DoAfterDocumentSave();
|
||||
|
||||
|
||||
typedef enum {
|
||||
eDocumentCreated,
|
||||
eDocumentToBeDestroyed,
|
||||
eDocumentStateChanged
|
||||
} TDocumentListenerNotification;
|
||||
|
||||
// tell the doc state listeners that the doc state has changed
|
||||
NS_IMETHOD NotifyDocumentListeners(TDocumentListenerNotification aNotificationType);
|
||||
|
||||
/** make the given selection span the entire document */
|
||||
NS_IMETHOD SelectEntireDocument(nsIDOMSelection *aSelection);
|
||||
|
||||
protected:
|
||||
// XXXX: Horrible hack! We are doing this because
|
||||
// of an error in Gecko which is not rendering the
|
||||
// document after a change via the DOM - gpk 2/13/99
|
||||
void HACKForceRedraw(void);
|
||||
|
||||
// file handling utils
|
||||
|
||||
NS_IMETHOD SaveDocument(PRBool saveAs, PRBool saveCopy);
|
||||
|
||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
|
||||
|
||||
public:
|
||||
|
||||
static nsString& GetTextNodeTag();
|
||||
|
||||
/**
|
||||
* SplitNode() creates a new node identical to an existing node, and split the contents between the two nodes
|
||||
* @param aExistingRightNode the node to split. It will become the new node's next sibling.
|
||||
* @param aOffset the offset of aExistingRightNode's content|children to do the split at
|
||||
* @param aNewLeftNode [OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
|
||||
* @param aParent the parent of aExistingRightNode
|
||||
*/
|
||||
static nsresult SplitNodeImpl(nsIDOMNode *aExistingRightNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMNode *aNewLeftNode,
|
||||
nsIDOMNode *aParent);
|
||||
|
||||
/**
|
||||
* JoinNodes() takes 2 nodes and merge their content|children.
|
||||
* @param aNodeToKeep The node that will remain after the join.
|
||||
* @param aNodeToJoin The node that will be joined with aNodeToKeep.
|
||||
* There is no requirement that the two nodes be of the same type.
|
||||
* @param aParent The parent of aExistingRightNode
|
||||
* @param aNodeToKeepIsFirst if PR_TRUE, the contents|children of aNodeToKeep come before the
|
||||
* contents|children of aNodeToJoin, otherwise their positions are switched.
|
||||
*/
|
||||
static nsresult JoinNodesImpl(nsIDOMNode *aNodeToKeep,
|
||||
nsIDOMNode *aNodeToJoin,
|
||||
nsIDOMNode *aParent,
|
||||
PRBool aNodeToKeepIsFirst);
|
||||
|
||||
/**
|
||||
* Set aOffset to the offset of aChild in aParent.
|
||||
* Returns an error if aChild is not an immediate child of aParent.
|
||||
*/
|
||||
static nsresult GetChildOffset(nsIDOMNode *aChild,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 &aOffset);
|
||||
|
||||
/**
|
||||
* Set aParent to the parent of aChild.
|
||||
* Set aOffset to the offset of aChild in aParent.
|
||||
*/
|
||||
static nsresult GetNodeLocation(nsIDOMNode *aChild,
|
||||
nsCOMPtr<nsIDOMNode> *aParent,
|
||||
PRInt32 *aOffset);
|
||||
|
||||
/** set aIsInline to PR_TRUE if aNode is inline as defined by HTML DTD */
|
||||
static nsresult IsNodeInline(nsIDOMNode *aNode, PRBool &aIsInline);
|
||||
|
||||
/** set aIsBlock to PR_TRUE if aNode is inline as defined by HTML DTD */
|
||||
static nsresult IsNodeBlock(nsIDOMNode *aNode, PRBool &aIsBlock);
|
||||
|
||||
/** returns the closest block parent of aNode, not including aNode itself.
|
||||
* can return null, for example if aNode is in a document fragment.
|
||||
* @param aNode The node whose parent we seek.
|
||||
* @param aBlockParent [OUT] The block parent, if any.
|
||||
* @return a success value unless an unexpected error occurs.
|
||||
*/
|
||||
static nsresult GetBlockParent(nsIDOMNode *aNode,
|
||||
nsIDOMElement **aBlockParent);
|
||||
|
||||
/** Determines the bounding nodes for the block section containing aNode.
|
||||
* The calculation is based on some nodes intrinsically being block elements
|
||||
* acording to HTML. Style sheets are not considered in this calculation.
|
||||
* <BR> tags separate block content sections. So the HTML markup:
|
||||
* <PRE>
|
||||
* <P>text1<BR>text2<B>text3</B></P>
|
||||
* </PRE>
|
||||
* contains two block content sections. The first has the text node "text1"
|
||||
* for both endpoints. The second has "text2" as the left endpoint and
|
||||
* "text3" as the right endpoint.
|
||||
* Notice that offsets aren't required, only leaf nodes. Offsets are implicit.
|
||||
*
|
||||
* @param aNode the block content returned includes aNode
|
||||
* @param aLeftNode [OUT] the left endpoint of the block content containing aNode
|
||||
* @param aRightNode [OUT] the right endpoint of the block content containing aNode
|
||||
*
|
||||
*/
|
||||
static nsresult GetBlockSection(nsIDOMNode *aNode,
|
||||
nsIDOMNode **aLeftNode,
|
||||
nsIDOMNode **aRightNode);
|
||||
|
||||
/** Compute the set of block sections in a given range.
|
||||
* A block section is the set of (leftNode, rightNode) pairs given
|
||||
* by GetBlockSection. The set is computed by computing the
|
||||
* block section for every leaf node in the range and throwing
|
||||
* out duplicates.
|
||||
*
|
||||
* @param aRange The range to compute block sections for.
|
||||
* @param aSections Allocated storage for the resulting set, stored as nsIDOMRanges.
|
||||
*/
|
||||
static nsresult GetBlockSectionsForRange(nsIDOMRange *aRange,
|
||||
nsISupportsArray *aSections);
|
||||
|
||||
/** returns PR_TRUE in out-param aResult if all nodes between (aStartNode, aStartOffset)
|
||||
* and (aEndNode, aEndOffset) are inline as defined by HTML DTD.
|
||||
*/
|
||||
static nsresult IntermediateNodesAreInline(nsIDOMRange *aRange,
|
||||
nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
PRBool &aResult);
|
||||
|
||||
/** returns the number of things inside aNode in the out-param aCount.
|
||||
* @param aNode is the node to get the length of.
|
||||
* If aNode is text, returns number of characters.
|
||||
* If not, returns number of children nodes.
|
||||
* @param aCount [OUT] the result of the above calculation.
|
||||
*/
|
||||
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount);
|
||||
|
||||
/** get the node immediately prior to aCurrentNode
|
||||
* @param aCurrentNode the node from which we start the search
|
||||
* @param aEditableNode if PR_TRUE, only return an editable node
|
||||
* @param aResultNode [OUT] the node that occurs before aCurrentNode in the tree,
|
||||
* skipping non-editable nodes if aEditableNode is PR_TRUE.
|
||||
* If there is no prior node, aResultNode will be nsnull.
|
||||
*/
|
||||
nsresult GetPriorNode(nsIDOMNode *aCurrentNode,
|
||||
PRBool aEditableNode,
|
||||
nsIDOMNode **aResultNode);
|
||||
|
||||
/** get the node immediately after to aCurrentNode
|
||||
* @param aCurrentNode the node from which we start the search
|
||||
* @param aEditableNode if PR_TRUE, only return an editable node
|
||||
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the tree,
|
||||
* skipping non-editable nodes if aEditableNode is PR_TRUE.
|
||||
* If there is no prior node, aResultNode will be nsnull.
|
||||
*/
|
||||
nsresult GetNextNode(nsIDOMNode *aCurrentNode,
|
||||
PRBool aEditableNode,
|
||||
nsIDOMNode **aResultNode);
|
||||
|
||||
/** Get the rightmost child of aCurrentNode, and return it in aResultNode
|
||||
* aResultNode is set to nsnull if aCurrentNode has no children.
|
||||
*/
|
||||
static nsresult GetRightmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
/** Get the leftmost child of aCurrentNode, and return it in aResultNode
|
||||
* aResultNode is set to nsnull if aCurrentNode has no children.
|
||||
*/
|
||||
static nsresult GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
/** GetFirstTextNode ADDREFFS and will get the next available text node from the passed
|
||||
* in node parameter it can also return NS_ERROR_FAILURE if no text nodes are available
|
||||
* now it simply returns the first node in the dom
|
||||
* @param nsIDOMNode *aNode is the node to start looking from
|
||||
* @param nsIDOMNode **aRetNode is the return location of the text dom node
|
||||
*
|
||||
* NOTE: this method will probably be removed.
|
||||
*/
|
||||
static nsresult GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode);
|
||||
|
||||
/** GetFirstNodeOfType ADDREFFS and will get the next available node from the passed
|
||||
* in aStartNode parameter of type aTag.
|
||||
* It can also return NS_ERROR_FAILURE if no such nodes are available
|
||||
* @param aStartNode is the node to start looking from
|
||||
* @param aTag is the type of node we are searching for
|
||||
* @param aResult is the node we found, or nsnull if there is none
|
||||
*/
|
||||
static nsresult GetFirstNodeOfType(nsIDOMNode *aStartNode,
|
||||
const nsString &aTag,
|
||||
nsIDOMNode **aResult);
|
||||
|
||||
/** returns PR_TRUE if aNode is of the type implied by aTag */
|
||||
static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag);
|
||||
|
||||
/** returns PR_TRUE if aParent can contain a child of type aTag */
|
||||
PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag);
|
||||
|
||||
/** returns PR_TRUE if aNode is an editable node */
|
||||
PRBool IsEditable(nsIDOMNode *aNode);
|
||||
|
||||
/** counts number of editable child nodes */
|
||||
nsresult CountEditableChildren(nsIDOMNode *aNode, PRUint32 &outCount);
|
||||
|
||||
/** Find the deep first and last children */
|
||||
nsCOMPtr<nsIDOMNode> GetDeepFirstChild(nsCOMPtr<nsIDOMNode> aRoot);
|
||||
nsCOMPtr<nsIDOMNode> GetDeepLastChild(nsCOMPtr<nsIDOMNode> aRoot);
|
||||
|
||||
|
||||
/** from html rules code - migration in progress */
|
||||
static nsresult GetTagString(nsIDOMNode *aNode, nsString& outString);
|
||||
static nsCOMPtr<nsIAtom> GetTag(nsIDOMNode *aNode);
|
||||
static PRBool NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2);
|
||||
static PRBool IsBlockNode(nsIDOMNode *aNode);
|
||||
static PRBool IsInlineNode(nsIDOMNode *aNode);
|
||||
static nsCOMPtr<nsIDOMNode> GetBlockNodeParent(nsIDOMNode *aNode);
|
||||
static PRBool HasSameBlockNodeParent(nsIDOMNode *aNode1, nsIDOMNode *aNode2);
|
||||
|
||||
static PRBool IsTextOrElementNode(nsIDOMNode *aNode);
|
||||
static PRBool IsTextNode(nsIDOMNode *aNode);
|
||||
|
||||
static PRInt32 GetIndexOf(nsIDOMNode *aParent, nsIDOMNode *aChild);
|
||||
static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset);
|
||||
|
||||
static nsCOMPtr<nsIDOMNode> NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir);
|
||||
static nsresult GetStartNodeAndOffset(nsIDOMSelection *aSelection, nsCOMPtr<nsIDOMNode> *outStartNode, PRInt32 *outStartOffset);
|
||||
static nsresult GetEndNodeAndOffset(nsIDOMSelection *aSelection, nsCOMPtr<nsIDOMNode> *outEndNode, PRInt32 *outEndOffset);
|
||||
|
||||
nsresult IsPreformatted(nsIDOMNode *aNode, PRBool *aResult);
|
||||
nsresult IsNextCharWhitespace(nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool *aResult);
|
||||
nsresult IsPrevCharWhitespace(nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool *aResult);
|
||||
|
||||
nsresult SplitNodeDeep(nsIDOMNode *aNode, nsIDOMNode *aSplitPointParent, PRInt32 aSplitPointOffset);
|
||||
nsresult JoinNodeDeep(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMSelection *aSelection);
|
||||
|
||||
nsresult GetString(const nsString& name, nsString& value);
|
||||
|
||||
nsresult BeginUpdateViewBatch(void);
|
||||
nsresult EndUpdateViewBatch(void);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mFlags; // behavior flags. See nsIHighLevelHTMLEditor.h for the flags we use.
|
||||
|
||||
nsIPresShell *mPresShell;
|
||||
nsIViewManager *mViewManager;
|
||||
PRUint32 mUpdateCount;
|
||||
nsCOMPtr<nsITransactionManager> mTxnMgr;
|
||||
nsCOMPtr<nsIEditProperty> mEditProperty;
|
||||
nsCOMPtr<nsICSSStyleSheet> mLastStyleSheet; // is owning this dangerous?
|
||||
|
||||
//
|
||||
// data necessary to build IME transactions
|
||||
//
|
||||
nsCOMPtr<nsIDOMCharacterData> mIMETextNode;
|
||||
PRUint32 mIMETextOffset;
|
||||
PRUint32 mIMEBufferLength;
|
||||
|
||||
nsVoidArray* mActionListeners;
|
||||
nsCOMPtr<nsISupportsArray> mDocStateListeners;
|
||||
nsCOMPtr<nsIStringBundle> mStringBundle;
|
||||
|
||||
PRInt8 mDocDirtyState; // -1 = not initialized
|
||||
|
||||
nsIDOMDocument * mDoc;
|
||||
nsCOMPtr<nsIDTD> mDTD;
|
||||
// Services are not nsCOMPtr friendly
|
||||
nsIPref* mPrefs;
|
||||
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
nsJSEditorLog *mJSEditorLog;
|
||||
nsJSTxnLog *mJSTxnLog;
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
static PRInt32 gInstanceCount;
|
||||
|
||||
friend PRBool NSCanUnload(nsISupports* serviceMgr);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
1508
mozilla/editor/base/nsEditorEventListeners.cpp
Normal file
1508
mozilla/editor/base/nsEditorEventListeners.cpp
Normal file
File diff suppressed because it is too large
Load Diff
268
mozilla/editor/base/nsEditorEventListeners.h
Normal file
268
mozilla/editor/base/nsEditorEventListeners.h
Normal file
@@ -0,0 +1,268 @@
|
||||
/* -*- Mode: C++; 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef editorInterfaces_h__
|
||||
#define editorInterfaces_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMTextListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMCompositionListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
/** The nsTextEditorKeyListener public nsIDOMKeyListener
|
||||
* This class will delegate events to its editor according to the translation
|
||||
* it is responsible for. i.e. 'c' becomes a keydown, but 'ESC' becomes nothing.
|
||||
*/
|
||||
class nsTextEditorKeyListener : public nsIDOMKeyListener {
|
||||
public:
|
||||
/** the default constructor
|
||||
*/
|
||||
nsTextEditorKeyListener();
|
||||
/** the default destructor. virtual due to the possibility of derivation.
|
||||
*/
|
||||
virtual ~nsTextEditorKeyListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN interfaces in to the keylister base interface. must be supplied to handle pure virtual interfaces
|
||||
see the nsIDOMKeyListener interface implementation for details
|
||||
*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
|
||||
/*END interfaces from nsIDOMKeyListener*/
|
||||
|
||||
protected:
|
||||
virtual nsresult ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed);
|
||||
|
||||
protected:
|
||||
nsIEditor* mEditor; // weak reference
|
||||
};
|
||||
|
||||
|
||||
/** editor Implementation of the MouseListener interface
|
||||
*/
|
||||
class nsTextEditorTextListener : public nsIDOMTextListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
*/
|
||||
nsTextEditorTextListener();
|
||||
/** default destructor
|
||||
*/
|
||||
virtual ~nsTextEditorTextListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of textevent handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult HandleText(nsIDOMEvent* aTextEvent);
|
||||
/*END implementations of textevent handler interface*/
|
||||
|
||||
protected:
|
||||
nsIEditor* mEditor; // weak reference
|
||||
PRBool mCommitText;
|
||||
PRBool mInTransaction;
|
||||
};
|
||||
|
||||
|
||||
class nsIEditorIMESupport;
|
||||
|
||||
class nsTextEditorCompositionListener : public nsIDOMCompositionListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
*/
|
||||
nsTextEditorCompositionListener();
|
||||
/** default destructor
|
||||
*/
|
||||
virtual ~nsTextEditorCompositionListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor);
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of textevent handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult HandleStartComposition(nsIDOMEvent* aCompositionEvent);
|
||||
virtual nsresult HandleEndComposition(nsIDOMEvent* aCompositionEvent);
|
||||
/*END implementations of textevent handler interface*/
|
||||
|
||||
protected:
|
||||
nsIEditorIMESupport* mEditor; // weak reference
|
||||
};
|
||||
|
||||
|
||||
/** editor Implementation of the TextListener interface
|
||||
*/
|
||||
class nsTextEditorMouseListener : public nsIDOMMouseListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
*/
|
||||
nsTextEditorMouseListener();
|
||||
/** default destructor
|
||||
*/
|
||||
virtual ~nsTextEditorMouseListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of mouseevent handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
|
||||
/*END implementations of mouseevent handler interface*/
|
||||
|
||||
protected:
|
||||
nsIEditor* mEditor; // weak reference
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** editor Implementation of the MouseListener interface
|
||||
*/
|
||||
class nsTextEditorDragListener : public nsIDOMDragListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
*/
|
||||
nsTextEditorDragListener();
|
||||
/** default destructor
|
||||
*/
|
||||
virtual ~nsTextEditorDragListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of dragevent handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
|
||||
/*END implementations of dragevent handler interface*/
|
||||
|
||||
protected:
|
||||
nsIEditor* mEditor;
|
||||
|
||||
};
|
||||
|
||||
/** editor Implementation of the FocusListener interface
|
||||
*/
|
||||
class nsTextEditorFocusListener : public nsIDOMFocusListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
*/
|
||||
nsTextEditorFocusListener();
|
||||
/** default destructor
|
||||
*/
|
||||
virtual ~nsTextEditorFocusListener();
|
||||
|
||||
/** SetEditor gives an address to the editor that will be accessed
|
||||
* @param aEditor the editor this listener calls for editing operations
|
||||
*/
|
||||
void SetEditor(nsIEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of focus event handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult Focus(nsIDOMEvent* aEvent);
|
||||
virtual nsresult Blur(nsIDOMEvent* aEvent);
|
||||
/*END implementations of focus event handler interface*/
|
||||
|
||||
protected:
|
||||
nsIEditor* mEditor; // weak reference
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** factory for the editor key listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
/** factory for the editor mouse listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
/** factory for the editor text listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
/** factory for the editor drag listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
/** factory for the editor composition listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorCompositionListener(nsIDOMEventListener** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
/** factory for the editor composition listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorFocusListener(nsIDOMEventListener** aInstancePtrResult, nsIEditor *aEditor);
|
||||
|
||||
#endif //editorInterfaces_h__
|
||||
|
||||
150
mozilla/editor/base/nsEditorFactory.cpp
Normal file
150
mozilla/editor/base/nsEditorFactory.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsEditorFactory.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
#include "nsEditorShell.h"
|
||||
#include "nsEditorShellFactory.h"
|
||||
|
||||
#include "nsHTMLEditor.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
#include "nsEditorCID.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||
|
||||
|
||||
nsresult
|
||||
GetEditorFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
|
||||
// XXX Note static which never gets released, even on library unload.
|
||||
// XXX Was an nsCOMPtr but that caused a crash on exit,
|
||||
// XXX http://bugzilla.mozilla.org/show_bug.cgi?id=7938
|
||||
PR_EnterMonitor(GetEditorMonitor());
|
||||
|
||||
nsEditorFactory *factory = new nsEditorFactory(aClass);
|
||||
if (!factory)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
|
||||
if (!pNSIFactory)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(),
|
||||
(void **)aFactory);
|
||||
PR_ExitMonitor(GetEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
nsEditorFactory::nsEditorFactory(const nsCID &aClass)
|
||||
: mCID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsEditorFactory::~nsEditorFactory()
|
||||
{
|
||||
//nsComponentManager::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports
|
||||
|
||||
NS_METHOD
|
||||
nsEditorFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
NS_NOTREACHED("!nsEditor");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIFactory::GetIID()) ||
|
||||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsEditorFactory)
|
||||
NS_IMPL_RELEASE(nsEditorFactory)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_METHOD
|
||||
nsEditorFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsISupports *obj = nsnull;
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aOuter && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
|
||||
|
||||
/* nsEditor is pure virtual
|
||||
if (mCID.Equals(kEditorCID))
|
||||
obj = (nsISupports *)(nsIEditor*)new nsEditor();
|
||||
*/
|
||||
|
||||
if (mCID.Equals(kHTMLEditorCID))
|
||||
{
|
||||
//Need to cast to interface first to avoid "ambiguous conversion..." error
|
||||
// because of multiple nsISupports in the class hierarchy
|
||||
obj = (nsISupports *)(nsIHighLevelHTMLEditor*)new nsHTMLEditor();
|
||||
}
|
||||
|
||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||
{
|
||||
delete obj;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsEditorFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//if more than one person asks for the monitor at the same time for the FIRST time, we are screwed
|
||||
PRMonitor *GetEditorMonitor()
|
||||
{
|
||||
static PRMonitor *ns_editlock = nsnull;
|
||||
if (nsnull == ns_editlock)
|
||||
{
|
||||
ns_editlock = (PRMonitor *)1; //how long will the next line take? lets cut down on the chance of reentrancy
|
||||
ns_editlock = PR_NewMonitor();
|
||||
}
|
||||
else if ((PRMonitor *)1 == ns_editlock)
|
||||
return GetEditorMonitor();
|
||||
return ns_editlock;
|
||||
}
|
||||
67
mozilla/editor/base/nsEditorFactory.h
Normal file
67
mozilla/editor/base/nsEditorFactory.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsIEditFactory_h___
|
||||
#define nsIEditFactory_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
EditFactory that can make an editor
|
||||
*/
|
||||
|
||||
/**
|
||||
* This supplies the neccessary entrance to the edit module. it will return any
|
||||
* instantiations that we need.
|
||||
*/
|
||||
|
||||
nsresult GetEditorFactory(nsIFactory **aFactory, const nsCID & aClass);
|
||||
|
||||
class nsEditorFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports and AggregatedQueryInterface:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHOD
|
||||
CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD
|
||||
LockFactory(PRBool aLock);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsEditFactory:
|
||||
|
||||
virtual ~nsEditorFactory(void);
|
||||
private:
|
||||
nsEditorFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
|
||||
|
||||
/** getEditFactory
|
||||
* creates an edit factory other CSID supported friend functions here.
|
||||
*/
|
||||
friend nsresult GetEditorFactory(nsIFactory **, const nsCID & );
|
||||
const nsCID &mCID;
|
||||
};
|
||||
|
||||
#endif //nsIEditFactory_h___
|
||||
154
mozilla/editor/base/nsEditorRegistration.cpp
Normal file
154
mozilla/editor/base/nsEditorRegistration.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
#include "nsEditorCID.h"
|
||||
|
||||
#include "nsEditorShell.h" // for the CID
|
||||
#include "nsEditorShellFactory.h"
|
||||
|
||||
#include "nsEditor.h" // for gInstanceCount
|
||||
#include "nsEditorFactory.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||
static NS_DEFINE_IID(kEditorShellCID, NS_EDITORSHELL_CID);
|
||||
|
||||
|
||||
/*
|
||||
we must be good providers of factories etc. this is where to put ALL editor exports
|
||||
*/
|
||||
//BEGIN EXPORTS
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports * aServMgr,
|
||||
const nsCID & aClass,
|
||||
const char * aClassName,
|
||||
const char * aProgID,
|
||||
nsIFactory ** aFactory)
|
||||
{
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aFactory = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* componentManager = nsnull;
|
||||
rv = servMgr->GetService(kComponentManagerCID, nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&componentManager);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NOINTERFACE;
|
||||
|
||||
if (aClass.Equals(kHTMLEditorCID)) {
|
||||
rv = GetEditorFactory(aFactory, aClass);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
}
|
||||
else if (aClass.Equals(kEditorShellCID)) {
|
||||
rv = GetEditorShellFactory(aFactory, aClass, aClassName, aProgID);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, componentManager);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* aServMgr)
|
||||
{
|
||||
return nsEditor::gInstanceCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = compMgr->RegisterComponent(kHTMLEditorCID, NULL, NULL, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->RegisterComponent(kEditorShellCID,
|
||||
"Editor Shell Component",
|
||||
"component://netscape/editor/editorshell",
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->RegisterComponent(kEditorShellCID,
|
||||
"Editor Shell Spell Checker",
|
||||
"component://netscape/editor/editorspellcheck",
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
/*
|
||||
rv = compMgr->UnregisterComponent(kEditorCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->UnregisterComponent(kTextEditorCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
*/
|
||||
rv = compMgr->UnregisterComponent(kHTMLEditorCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->UnregisterComponent(kEditorShellCID, path);
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
//END EXPORTS
|
||||
|
||||
|
||||
2760
mozilla/editor/base/nsEditorShell.cpp
Normal file
2760
mozilla/editor/base/nsEditorShell.cpp
Normal file
File diff suppressed because it is too large
Load Diff
338
mozilla/editor/base/nsEditorShell.h
Normal file
338
mozilla/editor/base/nsEditorShell.h
Normal file
@@ -0,0 +1,338 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsEditorShell_h___
|
||||
#define nsEditorShell_h___
|
||||
|
||||
//#include "nsAppCores.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nsIEditorShell.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#ifdef NECKO
|
||||
#include "nsIPrompt.h"
|
||||
#else
|
||||
#include "nsINetSupport.h"
|
||||
#endif
|
||||
#include "nsIStreamObserver.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsTextServicesCID.h"
|
||||
#include "nsIEditorSpellCheck.h"
|
||||
#include "nsISpellChecker.h"
|
||||
#include "nsInterfaceState.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
class nsIBrowserWindow;
|
||||
class nsIWebShell;
|
||||
class nsIScriptContext;
|
||||
class nsIDOMWindow;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMNode;
|
||||
class nsIURI;
|
||||
class nsIWebShellWindow;
|
||||
class nsIPresShell;
|
||||
class nsIOutputStream;
|
||||
class nsISupportsArray;
|
||||
|
||||
|
||||
#define NS_EDITORSHELL_CID \
|
||||
{ /* {} */ \
|
||||
0x9afff72b, 0xca9a, 0x11d2, \
|
||||
{ 0x96, 0xc9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsEditorShell:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsEditorShell : public nsIEditorShell,
|
||||
public nsIEditorSpellCheck,
|
||||
public nsIDocumentLoaderObserver
|
||||
{
|
||||
public:
|
||||
|
||||
nsEditorShell();
|
||||
virtual ~nsEditorShell();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD Init();
|
||||
// NS_IMETHOD GetId(nsString& aId); // { return nsBaseAppCore::GetId(aId); }
|
||||
// NS_IMETHOD SetDocumentCharset(const nsString& aCharset); // { return nsBaseAppCore::SetDocumentCharset(aCharset); }
|
||||
|
||||
|
||||
/* nsIEditorShell interface */
|
||||
|
||||
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
||||
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||
|
||||
NS_IMETHOD GetDocumentModified(PRBool *aDocumentModified);
|
||||
|
||||
NS_IMETHOD GetWrapColumn(PRInt32 *aWrapColumn);
|
||||
NS_IMETHOD SetWrapColumn(PRInt32 aWrapColumn);
|
||||
|
||||
NS_IMETHOD SetEditorType(const PRUnichar *editorType);
|
||||
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD SetContentWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD SetWebShellWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD LoadUrl(const PRUnichar *url);
|
||||
NS_IMETHOD RegisterDocumentStateListener(nsIDocumentStateListener *docListener);
|
||||
NS_IMETHOD UnregisterDocumentStateListener(nsIDocumentStateListener *docListener);
|
||||
|
||||
/* void NewWindow (); */
|
||||
NS_IMETHOD NewWindow();
|
||||
NS_IMETHOD Open();
|
||||
NS_IMETHOD Save();
|
||||
NS_IMETHOD SaveAs();
|
||||
NS_IMETHOD CloseWindow();
|
||||
NS_IMETHOD Print();
|
||||
NS_IMETHOD Exit();
|
||||
|
||||
NS_IMETHOD Undo();
|
||||
NS_IMETHOD Redo();
|
||||
NS_IMETHOD Cut();
|
||||
NS_IMETHOD Copy();
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
NS_IMETHOD PasteAsQuotation();
|
||||
NS_IMETHOD PasteAsCitedQuotation(const PRUnichar *cite);
|
||||
NS_IMETHOD InsertAsQuotation(const PRUnichar *quotedText);
|
||||
NS_IMETHOD InsertAsCitedQuotation(const PRUnichar *quotedText, const PRUnichar *cite);
|
||||
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD DeleteSelection(PRInt32 direction);
|
||||
|
||||
/* void Find (); */
|
||||
NS_IMETHOD Find();
|
||||
NS_IMETHOD FindNext();
|
||||
|
||||
/* void InsertText (in wstring textToInsert); */
|
||||
NS_IMETHOD InsertText(const PRUnichar *textToInsert);
|
||||
NS_IMETHOD InsertSource(const PRUnichar *sourceToInsert);
|
||||
NS_IMETHOD InsertBreak();
|
||||
NS_IMETHOD InsertList(const PRUnichar *listType);
|
||||
|
||||
/* void Indent (in string indent); */
|
||||
NS_IMETHOD Indent(const PRUnichar *indent);
|
||||
NS_IMETHOD Align(const PRUnichar *align);
|
||||
|
||||
/* nsIDOMElement GetSelectedElement (in wstring tagName); */
|
||||
NS_IMETHOD GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval);
|
||||
NS_IMETHOD GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *aNode, nsIDOMElement **_retval);
|
||||
NS_IMETHOD CreateElementWithDefaults(const PRUnichar *tagName, nsIDOMElement **_retval);
|
||||
NS_IMETHOD InsertElement(nsIDOMElement *element, PRBool deleteSelection);
|
||||
NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement);
|
||||
NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement *anchorElement);
|
||||
NS_IMETHOD SelectElement(nsIDOMElement *element);
|
||||
NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element);
|
||||
|
||||
/* Table insert and delete methods. Done relative to selected cell or
|
||||
cell containing the selection anchor */
|
||||
NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD InsertTableRow(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD DeleteTable();
|
||||
NS_IMETHOD DeleteTableCell(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
|
||||
NS_IMETHOD JoinTableCells();
|
||||
/** Make table "rectangular" -- fill in all missing cellmap locations
|
||||
* If aTable is null, it uses table enclosing the selection anchor
|
||||
*/
|
||||
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
|
||||
|
||||
/* Get the row and col indexes in layout's cellmap */
|
||||
NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 *_retval);
|
||||
NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 *_retval);
|
||||
/** Get the number of rows in a table from the layout's cellmap */
|
||||
NS_IMETHOD GetTableRowCount(nsIDOMElement *aTable, PRInt32 *_retval);
|
||||
/** Get the number of columns in a table from the layout's cellmap */
|
||||
NS_IMETHOD GetTableColumnCount(nsIDOMElement *aTable, PRInt32 *_retval);
|
||||
|
||||
/* Get a cell and associated data from the layout frame based on cell map coordinates (0 index) */
|
||||
NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement **_retval);
|
||||
/* Note that the return param in the IDL must be the LAST out param here (_retval) */
|
||||
NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
|
||||
PRInt32 *aStartRowIndex, PRInt32 *aStartColIndex,
|
||||
PRInt32 *aRowSpan, PRInt32 *aColSpan, PRBool *aIsSelected, nsIDOMElement **_retval);
|
||||
|
||||
/* Get list of embedded objects, e.g. for mail compose */
|
||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray);
|
||||
|
||||
/* void SetParagraphFormat (in string value); */
|
||||
NS_IMETHOD SetParagraphFormat(PRUnichar *value);
|
||||
NS_IMETHOD GetParagraphFormat(PRUnichar * *aParagraphFormat);
|
||||
|
||||
/* void SetTextProperty (in string prop, in string attr, in string value); */
|
||||
NS_IMETHOD SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value);
|
||||
NS_IMETHOD GetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value, PRBool *firstHas, PRBool *anyHas, PRBool *allHas);
|
||||
NS_IMETHOD RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr);
|
||||
|
||||
/* void SetBodyAttribute (in string attr, in string value); */
|
||||
NS_IMETHOD SetBodyAttribute(const PRUnichar *attr, const PRUnichar *value);
|
||||
NS_IMETHOD SetBackgroundColor(const PRUnichar *color);
|
||||
|
||||
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
||||
|
||||
/* Get the contents, for output or other uses */
|
||||
NS_IMETHOD GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs);
|
||||
|
||||
/* Debugging: dump content tree to stdout */
|
||||
NS_IMETHOD DumpContentTree();
|
||||
|
||||
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
||||
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
||||
|
||||
/* void BeginBatchChanges (); */
|
||||
NS_IMETHOD BeginBatchChanges();
|
||||
NS_IMETHOD EndBatchChanges();
|
||||
|
||||
/* void RunUnitTests (); */
|
||||
NS_IMETHOD RunUnitTests();
|
||||
|
||||
/* void BeginLogging (); */
|
||||
NS_IMETHOD StartLogging(nsIFileSpec *logFile);
|
||||
NS_IMETHOD StopLogging();
|
||||
|
||||
|
||||
/* Spell check interface */
|
||||
NS_IMETHOD StartSpellChecking(PRUnichar **_retval);
|
||||
NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval);
|
||||
NS_IMETHOD GetSuggestedWord(PRUnichar **_retval);
|
||||
NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval);
|
||||
NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences);
|
||||
NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word);
|
||||
NS_IMETHOD GetPersonalDictionary();
|
||||
NS_IMETHOD GetPersonalDictionaryWord(PRUnichar **_retval);
|
||||
NS_IMETHOD AddWordToDictionary(const PRUnichar *word);
|
||||
NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word);
|
||||
NS_IMETHOD CloseSpellChecking();
|
||||
|
||||
|
||||
// nsIDocumentLoaderObserver
|
||||
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aCommand);
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIURI *aUrl, PRInt32 aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver);
|
||||
#else
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRInt32 aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aContentType,
|
||||
nsIContentViewer* aViewer);
|
||||
#else
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsIContentViewer* aViewer);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
#else
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, nsString& aMsg);
|
||||
#else
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsString& aMsg);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, PRInt32 aStatus);
|
||||
#else
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRInt32 aStatus);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIURI *aURL,
|
||||
const char *aContentType,
|
||||
const char *aCommand );
|
||||
#else
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
const char *aContentType,
|
||||
const char *aCommand );
|
||||
#endif // NECKO
|
||||
|
||||
protected:
|
||||
nsIDOMWindow *mToolbarWindow; // weak reference
|
||||
nsIDOMWindow *mContentWindow; // weak reference
|
||||
|
||||
nsIWebShellWindow *mWebShellWin; // weak reference
|
||||
nsIWebShell *mWebShell; // weak reference
|
||||
nsIWebShell *mContentAreaWebShell; // weak reference
|
||||
|
||||
typedef enum {
|
||||
eUninitializedEditorType = 0,
|
||||
ePlainTextEditorType = 1,
|
||||
eHTMLTextEditorType = 2
|
||||
} EEditorType;
|
||||
|
||||
nsIPresShell* GetPresShellFor(nsIWebShell* aWebShell);
|
||||
NS_IMETHOD DoEditorMode(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
|
||||
NS_IMETHOD InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
NS_IMETHOD TransferDocumentStateListeners();
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
|
||||
NS_IMETHOD CreateWindowWithURL(const char* urlStr);
|
||||
NS_IMETHOD PrepareDocumentForEditing(nsIURI *aUrl);
|
||||
NS_IMETHOD DoFind(PRBool aFindNext);
|
||||
|
||||
// this returns an AddReffed nsIScriptContext. You must relase it.
|
||||
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
|
||||
|
||||
nsString mEnableScript;
|
||||
nsString mDisableScript;
|
||||
|
||||
EEditorType mEditorType;
|
||||
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
|
||||
nsCOMPtr<nsIHighLevelHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
|
||||
|
||||
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
||||
|
||||
nsInterfaceState* mStateMaintainer; // we hold the owning ref to this.
|
||||
|
||||
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
|
||||
|
||||
nsCOMPtr<nsISpellChecker> mSpellChecker;
|
||||
nsStringArray mSuggestedWordList;
|
||||
PRInt32 mSuggestedWordIndex;
|
||||
NS_IMETHOD DeleteSuggestedWordList();
|
||||
nsStringArray mDictionaryList;
|
||||
PRInt32 mDictionaryIndex;
|
||||
|
||||
// this is a holding pen for doc state listeners. They will be registered with
|
||||
// the editor when that gets created.
|
||||
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
|
||||
};
|
||||
|
||||
#endif // nsEditorShell_h___
|
||||
212
mozilla/editor/base/nsEditorShellFactory.cpp
Normal file
212
mozilla/editor/base/nsEditorShellFactory.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsEditorShellFactory.h"
|
||||
#include "nsEditorShell.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPComFactory.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kEditorShellCID, NS_EDITORSHELL_CID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// nsEditorShellFactoryImpl
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsEditorShellFactoryImpl::nsEditorShellFactoryImpl(const nsCID &aClass,
|
||||
const char* className,
|
||||
const char* progID)
|
||||
: mClassID(aClass), mClassName(className), mProgID(progID)
|
||||
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsEditorShellFactoryImpl::~nsEditorShellFactoryImpl(void)
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShellFactoryImpl::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if ( aIID.Equals(kISupportsIID) )
|
||||
{
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*, this);
|
||||
}
|
||||
else if ( aIID.Equals(kIFactoryIID) )
|
||||
{
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIFactory*, this);
|
||||
}
|
||||
|
||||
if (*aInstancePtr == NULL)
|
||||
{
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsEditorShellFactoryImpl)
|
||||
NS_IMPL_RELEASE(nsEditorShellFactoryImpl)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShellFactoryImpl::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kEditorShellCID)) {
|
||||
if (NS_FAILED(rv = NS_NewEditorShell((nsIEditorShell**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult))) {
|
||||
// We didn't get the right interface.
|
||||
NS_ERROR("didn't support the interface you wanted");
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(inst);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShellFactoryImpl::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
GetEditorShellFactory(nsIFactory **aFactory, const nsCID &aClass, const char *aClassName, const char *aProgID)
|
||||
{
|
||||
PR_EnterMonitor(GetEditorMonitor());
|
||||
|
||||
nsEditorShellFactoryImpl* factory = new nsEditorShellFactoryImpl(aClass, aClassName, aProgID);
|
||||
if (!factory)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIFactory> pNSIFactory (do_QueryInterface(factory));
|
||||
if (!pNSIFactory)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsresult result = pNSIFactory->QueryInterface(kIFactoryIID,
|
||||
(void **)aFactory);
|
||||
PR_ExitMonitor(GetEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//#define EDITOR_SHELL_STANDALONE
|
||||
|
||||
#if EDITOR_SHELL_STANDALONE
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsEditorShellFactoryImpl* factory = new nsEditorShellFactoryImpl(aClass, aClassName, aProgID);
|
||||
if (factory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kEditorAppCoreCID,
|
||||
"Editor Shell Component",
|
||||
"component://netscape/editor/editorshell",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kEditorAppCoreCID, aPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
60
mozilla/editor/base/nsEditorShellFactory.h
Normal file
60
mozilla/editor/base/nsEditorShellFactory.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsEditorAppCoreFactory_h___
|
||||
#define nsEditorAppCoreFactory_h___
|
||||
|
||||
//#include "nscore.h"
|
||||
//#include "nsString.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsEditorAppCoreFactory:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsEditorShellFactoryImpl : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsEditorShellFactoryImpl(const nsCID &aClass, const char* className, const char* progID);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
PRBool CanUnload(void);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID& aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~nsEditorShellFactoryImpl();
|
||||
|
||||
protected:
|
||||
nsCID mClassID;
|
||||
const char* mClassName;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
nsresult
|
||||
GetEditorShellFactory(nsIFactory **aFactory, const nsCID &aClass, const char *aClassName, const char *aProgID);
|
||||
|
||||
#endif // nsEditorAppCoreFactory_h___
|
||||
52
mozilla/editor/base/nsEditorUtils.cpp
Normal file
52
mozilla/editor/base/nsEditorUtils.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsEditorUtils.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsAutoSelectionReset
|
||||
*****************************************************************************/
|
||||
|
||||
nsAutoSelectionReset::nsAutoSelectionReset(nsIDOMSelection *aSel)
|
||||
{
|
||||
mInitialized = PR_FALSE;
|
||||
mSel = do_QueryInterface(aSel);
|
||||
if (mSel)
|
||||
{
|
||||
mSel->GetAnchorNode(getter_AddRefs(mStartNode));
|
||||
mSel->GetAnchorOffset(&mStartOffset);
|
||||
mSel->GetFocusNode(getter_AddRefs(mEndNode));
|
||||
mSel->GetFocusOffset(&mEndOffset);
|
||||
if (mStartNode && mEndNode)
|
||||
mInitialized = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
nsAutoSelectionReset::~nsAutoSelectionReset()
|
||||
{
|
||||
if (mSel && mInitialized)
|
||||
{
|
||||
// restore original selection
|
||||
mSel->Collapse(mStartNode, mStartOffset);
|
||||
mSel->Extend(mEndNode, mEndOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
62
mozilla/editor/base/nsEditorUtils.h
Normal file
62
mozilla/editor/base/nsEditorUtils.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsEditorUtils_h__
|
||||
#define nsEditorUtils_h__
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIEditor.h"
|
||||
|
||||
class nsAutoEditBatch
|
||||
{
|
||||
private:
|
||||
nsCOMPtr<nsIEditor> mEd;
|
||||
public:
|
||||
nsAutoEditBatch( nsIEditor *aEd) : mEd(do_QueryInterface(aEd))
|
||||
{ if (mEd) mEd->BeginTransaction(); }
|
||||
~nsAutoEditBatch() { if (mEd) mEd->EndTransaction(); }
|
||||
};
|
||||
|
||||
class nsAutoSelectionReset
|
||||
{
|
||||
private:
|
||||
/** ref-counted reference to the selection that we are supposed to restore */
|
||||
nsCOMPtr<nsIDOMSelection> mSel;
|
||||
|
||||
/** PR_TRUE if this instance initialized itself correctly */
|
||||
PRBool mInitialized;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> mStartNode;
|
||||
nsCOMPtr<nsIDOMNode> mEndNode;
|
||||
PRInt32 mStartOffset;
|
||||
PRInt32 mEndOffset;
|
||||
|
||||
public:
|
||||
/** constructor responsible for remembering all state needed to restore aSel */
|
||||
nsAutoSelectionReset(nsIDOMSelection *aSel);
|
||||
|
||||
/** destructor restores mSel to its former state */
|
||||
~nsAutoSelectionReset();
|
||||
};
|
||||
|
||||
|
||||
#endif // nsEditorUtils_h__
|
||||
132
mozilla/editor/base/nsHTMLEditFactory.cpp
Normal file
132
mozilla/editor/base/nsHTMLEditFactory.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsHTMLEditFactory.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsHTMLEditor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsEditorCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kIHTMLEditorIID, NS_IHTMLEDITOR_IID);
|
||||
static NS_DEFINE_IID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||
static NS_DEFINE_IID(kIHTMLEditFactoryIID, NS_IHTMLEDITORFACTORY_IID);
|
||||
|
||||
|
||||
nsresult
|
||||
GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
PR_EnterMonitor(GetEditorMonitor());
|
||||
|
||||
nsHTMLEditFactory *factory = new nsHTMLEditFactory(aClass);
|
||||
if (!factory)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
|
||||
if (!pNSIFactory)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsresult result = pNSIFactory->QueryInterface(kIFactoryIID,
|
||||
(void **)aFactory);
|
||||
PR_ExitMonitor(GetEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
NS_NOTREACHED("!nsEditor");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTMLEditFactory)
|
||||
NS_IMPL_RELEASE(nsHTMLEditFactory)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsISupports *obj = nsnull;
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aOuter && !aIID.Equals(kISupportsIID))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
|
||||
|
||||
if (mCID.Equals(kHTMLEditorCID))
|
||||
{
|
||||
//Need to cast to interface first to avoid "ambiguous conversion..." error
|
||||
// because of multiple nsISupports in the class hierarchy
|
||||
obj = (nsISupports *)(nsIHTMLEditor*)new nsHTMLEditor();
|
||||
}
|
||||
//more class ids to support. here
|
||||
|
||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||
{
|
||||
delete obj;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsHTMLEditFactory::nsHTMLEditFactory(const nsCID &aClass)
|
||||
:mCID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsHTMLEditFactory::~nsHTMLEditFactory()
|
||||
{
|
||||
//nsComponentManager::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
66
mozilla/editor/base/nsHTMLEditFactory.h
Normal file
66
mozilla/editor/base/nsHTMLEditFactory.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsHTMLEditFactory_h___
|
||||
#define nsHTMLEditFactory_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
Factory that can make a text editor
|
||||
*/
|
||||
|
||||
/**
|
||||
* This supplies the neccessary entrance to the edit module. it will return any
|
||||
* instantiations that we need.
|
||||
*/
|
||||
class nsHTMLEditFactory;
|
||||
|
||||
extern nsresult GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass);
|
||||
|
||||
class nsHTMLEditFactory : public nsIFactory {
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports and AggregatedQueryInterface:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHOD
|
||||
CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD
|
||||
LockFactory(PRBool aLock);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual ~nsHTMLEditFactory(void);
|
||||
private:
|
||||
nsHTMLEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
|
||||
|
||||
/** GetHTMLEditFactory
|
||||
* creates an edit factory other CSID supported friend functions here.
|
||||
*/
|
||||
friend nsresult GetHTMLEditFactory(nsIFactory **, const nsCID & );
|
||||
const nsCID &mCID;
|
||||
};
|
||||
|
||||
#endif //nsIEditFactory_h___
|
||||
1843
mozilla/editor/base/nsHTMLEditRules.cpp
Normal file
1843
mozilla/editor/base/nsHTMLEditRules.cpp
Normal file
File diff suppressed because it is too large
Load Diff
115
mozilla/editor/base/nsHTMLEditRules.h
Normal file
115
mozilla/editor/base/nsHTMLEditRules.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsHTMLEditRules_h__
|
||||
#define nsHTMLEditRules_h__
|
||||
|
||||
#include "nsTextEditRules.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsISupportsArray;
|
||||
class nsVoidArray;
|
||||
|
||||
class nsHTMLEditRules : public nsTextEditRules
|
||||
{
|
||||
public:
|
||||
|
||||
nsHTMLEditRules(PRUint32 aFlags);
|
||||
virtual ~nsHTMLEditRules();
|
||||
|
||||
// nsEditRules methods
|
||||
NS_IMETHOD WillDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel);
|
||||
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
||||
|
||||
protected:
|
||||
|
||||
enum IterDirection
|
||||
{
|
||||
kIterForward,
|
||||
kIterBackward
|
||||
};
|
||||
|
||||
enum RulesEndpoint
|
||||
{
|
||||
kStart,
|
||||
kEnd
|
||||
};
|
||||
|
||||
|
||||
// nsHTMLEditRules implementation methods
|
||||
nsresult WillInsertText(nsIDOMSelection *aSelection,
|
||||
PRBool *aCancel,
|
||||
PlaceholderTxn **aTxn,
|
||||
const nsString *inString,
|
||||
nsString *outString,
|
||||
TypeInState typeInState,
|
||||
PRInt32 aMaxLength);
|
||||
nsresult WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult WillDeleteSelection(nsIDOMSelection *aSelection, nsIEditor::ESelectionCollapseDirection aAction, PRBool *aCancel);
|
||||
nsresult WillMakeList(nsIDOMSelection *aSelection, PRBool aOrderd, PRBool *aCancel);
|
||||
nsresult WillIndent(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult WillOutdent(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult WillAlign(nsIDOMSelection *aSelection, const nsString *alignType, PRBool *aCancel);
|
||||
nsresult WillMakeHeader(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult WillMakeAddress(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult WillMakePRE(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
|
||||
nsresult InsertTab(nsIDOMSelection *aSelection, PRBool *aCancel, PlaceholderTxn **aTxn, nsString *outString);
|
||||
nsresult InsertSpace(nsIDOMSelection *aSelection, PRBool *aCancel, PlaceholderTxn **aTxn, nsString *outString);
|
||||
|
||||
nsresult ReturnInHeader(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset);
|
||||
nsresult ReturnInParagraph(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset, PRBool *aCancel);
|
||||
nsresult ReturnInListItem(nsIDOMSelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset);
|
||||
|
||||
// helper methods
|
||||
static nsresult GetTabAsNBSPs(nsString *outString);
|
||||
static nsresult GetTabAsNBSPsAndSpace(nsString *outString);
|
||||
|
||||
static PRBool IsHeader(nsIDOMNode *aNode);
|
||||
static PRBool IsParagraph(nsIDOMNode *aNode);
|
||||
static PRBool IsListItem(nsIDOMNode *aNode);
|
||||
static PRBool IsUnorderedList(nsIDOMNode *aNode);
|
||||
static PRBool IsOrderedList(nsIDOMNode *aNode);
|
||||
static PRBool IsBreak(nsIDOMNode *aNode);
|
||||
static PRBool IsBody(nsIDOMNode *aNode);
|
||||
static PRBool IsBlockquote(nsIDOMNode *aNode);
|
||||
static PRBool IsDiv(nsIDOMNode *aNode);
|
||||
|
||||
PRBool IsFirstNode(nsIDOMNode *aNode);
|
||||
PRBool IsLastNode(nsIDOMNode *aNode);
|
||||
nsresult GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset,
|
||||
PRInt32 actionID, nsCOMPtr<nsIDOMNode> *outNode, PRInt32 *outOffset);
|
||||
|
||||
nsresult GetPromotedRanges(nsIDOMSelection *inSelection,
|
||||
nsCOMPtr<nsISupportsArray> *outArrayOfRanges,
|
||||
PRInt32 inOperationType);
|
||||
static nsresult GetNodesForOperation(nsISupportsArray *inArrayOfRanges,
|
||||
nsCOMPtr<nsISupportsArray> *outArrayOfNodes,
|
||||
PRInt32 inOperationType);
|
||||
static nsresult MakeTransitionList(nsISupportsArray *inArrayOfNodes,
|
||||
nsVoidArray *inTransitionArray);
|
||||
|
||||
nsresult ReplaceContainer(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, nsString &aNodeType);
|
||||
nsresult RemoveContainer(nsIDOMNode *inNode);
|
||||
nsresult InsertContainerAbove(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, nsString &aNodeType);
|
||||
|
||||
};
|
||||
|
||||
#endif //nsHTMLEditRules_h__
|
||||
|
||||
5677
mozilla/editor/base/nsHTMLEditor.cpp
Normal file
5677
mozilla/editor/base/nsHTMLEditor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
434
mozilla/editor/base/nsHTMLEditor.h
Normal file
434
mozilla/editor/base/nsHTMLEditor.h
Normal file
@@ -0,0 +1,434 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsHTMLEditor_h__
|
||||
#define nsHTMLEditor_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
#include "nsITableEditor.h"
|
||||
#include "nsIEditorMailSupport.h"
|
||||
#include "nsIEditorStyleSheets.h"
|
||||
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsITableLayout.h"
|
||||
|
||||
#include "TypeInState.h"
|
||||
#include "nsEditRules.h"
|
||||
|
||||
/**
|
||||
* The HTML editor implementation.<br>
|
||||
* Use to edit HTML document represented as a DOM tree.
|
||||
*/
|
||||
class nsHTMLEditor : public nsEditor,
|
||||
public nsIHighLevelHTMLEditor,
|
||||
public nsIEditorMailSupport,
|
||||
public nsITableEditor,
|
||||
public nsIEditorStyleSheets
|
||||
{
|
||||
|
||||
typedef enum {eNoOp, eReplaceParent=1, eInsertParent=2} BlockTransformationType;
|
||||
|
||||
public:
|
||||
// see nsIHTMLEditor for documentation
|
||||
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE macro used is for classes that inherit from
|
||||
// another class. Only the base class should use NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsHTMLEditor();
|
||||
virtual ~nsHTMLEditor();
|
||||
|
||||
/* ------------ nsIHighLevelHTMLEditor methods -------------- */
|
||||
|
||||
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
|
||||
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
|
||||
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);
|
||||
|
||||
|
||||
NS_IMETHOD SetInlineProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD GetInlineProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAny, PRBool &aAll);
|
||||
|
||||
NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD InsertBreak();
|
||||
NS_IMETHOD InsertText(const nsString& aStringToInsert);
|
||||
NS_IMETHOD InsertHTML(const nsString &aInputString);
|
||||
NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection);
|
||||
|
||||
NS_IMETHOD DeleteSelection(ESelectionCollapseDirection aAction);
|
||||
NS_IMETHOD DeleteSelectionAndCreateNode(const nsString& aTag, nsIDOMNode ** aNewNode);
|
||||
NS_IMETHOD SelectElement(nsIDOMElement* aElement);
|
||||
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement);
|
||||
|
||||
NS_IMETHOD GetParagraphFormat(nsString& aParagraphFormat);
|
||||
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
|
||||
|
||||
NS_IMETHOD GetParagraphStyle(nsStringArray *aTagList);
|
||||
NS_IMETHOD RemoveParagraphStyle();
|
||||
|
||||
NS_IMETHOD AddBlockParent(nsString& aParentTag);
|
||||
NS_IMETHOD ReplaceBlockParent(nsString& aParentTag);
|
||||
NS_IMETHOD RemoveParent(const nsString &aParentTag);
|
||||
|
||||
NS_IMETHOD InsertList(const nsString& aListType);
|
||||
NS_IMETHOD Indent(const nsString& aIndent);
|
||||
NS_IMETHOD Align(const nsString& aAlign);
|
||||
|
||||
NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn);
|
||||
NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn);
|
||||
NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn);
|
||||
|
||||
NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement);
|
||||
NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement);
|
||||
|
||||
|
||||
/* ------------ nsIEditorStyleSheets methods -------------- */
|
||||
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||
NS_IMETHOD AddStyleSheet(nsICSSStyleSheet* aSheet);
|
||||
NS_IMETHOD RemoveStyleSheet(nsICSSStyleSheet* aSheet);
|
||||
|
||||
/* ------------ nsIEditorMailSupport methods -------------- */
|
||||
|
||||
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
|
||||
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn);
|
||||
NS_IMETHOD PasteAsQuotation();
|
||||
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
|
||||
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation);
|
||||
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCitation);
|
||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList);
|
||||
|
||||
|
||||
/* ------------ nsITableEditor methods -------------- */
|
||||
|
||||
|
||||
NS_IMETHOD InsertTable();
|
||||
NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD InsertTableRow(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD DeleteTable();
|
||||
NS_IMETHOD DeleteTableCell(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
|
||||
NS_IMETHOD JoinTableCells(PRBool aCellToRight);
|
||||
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
|
||||
NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex);
|
||||
NS_IMETHOD GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& aColCount);
|
||||
NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell);
|
||||
NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell,
|
||||
PRInt32& aStartRowIndex, PRInt32& aStartColIndex,
|
||||
PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected);
|
||||
|
||||
|
||||
// Selection and navigation
|
||||
/* obsolete
|
||||
NS_IMETHOD MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD ScrollUp(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollDown(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
|
||||
*/
|
||||
|
||||
/* miscellaneous */
|
||||
// This sets background on the appropriate container element (table, cell,)
|
||||
// or calls into nsTextEditor to set the page background
|
||||
NS_IMETHOD SetBackgroundColor(const nsString& aColor);
|
||||
NS_IMETHOD SetBodyAttribute(const nsString& aAttr, const nsString& aValue);
|
||||
|
||||
|
||||
|
||||
/* ------------ Overrides of nsEditor interface methods -------------- */
|
||||
|
||||
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD Cut();
|
||||
NS_IMETHOD Copy();
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void InitRules();
|
||||
|
||||
NS_IMETHOD GetLayoutObject(nsIDOMNode *aNode, nsISupports **aLayoutObject);
|
||||
|
||||
NS_IMETHOD DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parentSelectedNode, PRInt32& offsetOfNewNode);
|
||||
|
||||
/* StyleSheet load callback */
|
||||
static void ApplyStyleSheetToPresShellDocument(nsICSSStyleSheet* aSheet, void *aData);
|
||||
|
||||
/* remove the old style sheet, and apply the supplied one */
|
||||
NS_IMETHOD ReplaceStyleSheet(nsICSSStyleSheet *aNewSheet);
|
||||
|
||||
|
||||
// Return TRUE if aElement is a table-related elemet and caret was set
|
||||
PRBool SetCaretInTableCell(nsIDOMElement* aElement);
|
||||
PRBool IsElementInBody(nsIDOMElement* aElement);
|
||||
|
||||
// Table Editing (implemented in EditTable.cpp)
|
||||
|
||||
// Helper used to get nsITableLayout interface for methods implemented in nsTableFrame
|
||||
NS_IMETHOD GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject);
|
||||
|
||||
// Table utilities
|
||||
|
||||
// All of the above need to get the same basic context data
|
||||
NS_IMETHOD GetCellContext(nsCOMPtr<nsIDOMSelection> &aSelection,
|
||||
nsCOMPtr<nsIDOMElement> &aTable, nsCOMPtr<nsIDOMElement> &aCell,
|
||||
nsCOMPtr<nsIDOMNode> &aCellParent, PRInt32& aCellOffset,
|
||||
PRInt32& aRow, PRInt32& aCol);
|
||||
|
||||
// Setting caret to a logical place can get tricky,
|
||||
// especially after deleting table stuff
|
||||
typedef enum { ePreviousColumn, ePreviousRow } SetCaretSearchDirection;
|
||||
|
||||
NS_IMETHOD SetCaretAfterTableEdit(nsIDOMElement* aTable, PRInt32 aCol, PRInt32 aRow, SetCaretSearchDirection aDirection);
|
||||
|
||||
NS_IMETHOD ReParentContentOfNode(nsIDOMNode *aNode,
|
||||
nsString &aParentTag,
|
||||
BlockTransformationType aTranformation);
|
||||
|
||||
NS_IMETHOD ReParentBlockContent(nsIDOMNode *aNode,
|
||||
nsString &aParentTag,
|
||||
nsIDOMNode *aBlockParentNode,
|
||||
nsString &aBlockParentTag,
|
||||
BlockTransformationType aTranformation,
|
||||
nsIDOMNode **aNewParentNode);
|
||||
|
||||
NS_IMETHOD ReParentContentOfRange(nsIDOMRange *aRange,
|
||||
nsString &aParentTag,
|
||||
BlockTransformationType aTranformation);
|
||||
|
||||
NS_IMETHOD RemoveParagraphStyleFromRange(nsIDOMRange *aRange);
|
||||
|
||||
NS_IMETHOD RemoveParagraphStyleFromBlockContent(nsIDOMRange *aRange);
|
||||
|
||||
NS_IMETHOD RemoveParentFromRange(const nsString &aParentTag, nsIDOMRange *aRange);
|
||||
|
||||
NS_IMETHOD RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRange *aRange);
|
||||
|
||||
NS_IMETHOD IsRootTag(nsString &aTag, PRBool &aIsTag);
|
||||
|
||||
NS_IMETHOD IsSubordinateBlock(nsString &aTag, PRBool &aIsTag);
|
||||
|
||||
|
||||
/** content-based query returns PR_TRUE if <aProperty aAttribute=aValue> effects aNode
|
||||
* If <aProperty aAttribute=aValue> contains aNode,
|
||||
* but <aProperty aAttribute=SomeOtherValue> also contains aNode and the second is
|
||||
* more deeply nested than the first, then the first does not effect aNode.
|
||||
*
|
||||
* @param aNode The target of the query
|
||||
* @param aProperty The property that we are querying for
|
||||
* @param aAttribute The attribute of aProperty, example: color in <FONT color="blue">
|
||||
* May be null.
|
||||
* @param aValue The value of aAttribute, example: blue in <FONT color="blue">
|
||||
* May be null. Ignored if aAttribute is null.
|
||||
* @param aIsSet [OUT] PR_TRUE if <aProperty aAttribute=aValue> effects aNode.
|
||||
* @param aStyleNode [OUT] set to the node representing <aProperty aAttribute=aValue>, if found.
|
||||
* null if aIsSet is returned as PR_FALSE;
|
||||
*/
|
||||
virtual void IsTextPropertySetByContent(nsIDOMNode *aNode,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aIsSet,
|
||||
nsIDOMNode **aStyleNode) const;
|
||||
|
||||
/** style-based query returns PR_TRUE if (aProperty, aAttribute) is set in aSC.
|
||||
* WARNING: not well tested yet since we don't do style-based queries anywhere.
|
||||
*/
|
||||
virtual void IsTextStyleSet(nsIStyleContext *aSC,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttributes,
|
||||
PRBool &aIsSet) const;
|
||||
|
||||
/** Moves the content between (aNode, aStartOffset) and (aNode, aEndOffset)
|
||||
* into aNewParentNode, splitting aNode as necessary to maintain the relative
|
||||
* position of all leaf content.
|
||||
* @param aNode The node whose content we're repositioning.
|
||||
* aNode can be either a text node or a container node.
|
||||
* @param aNewParentNode The node that will be the repositioned contents' parent.
|
||||
* The caller is responsible for allocating aNewParentNode
|
||||
* @param aStartOffset The start offset of the content of aNode
|
||||
* @param aEndOffset The end offset of the content of aNode.
|
||||
*/
|
||||
NS_IMETHOD MoveContentOfNodeIntoNewParent(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aNewParentNode,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset);
|
||||
|
||||
/** Moves the content between (aStartNode, aStartOffset) and (aEndNode, aEndOffset)
|
||||
* into aNewParentNode, splitting aStartNode and aEndNode as necessary to maintain
|
||||
* the relative position of all leaf content.
|
||||
* The content between the two endpoints MUST be "contiguous" in the sense that
|
||||
* it is all in the same block. Another way of saying this is all content nodes
|
||||
* between aStartNode and aEndNode must be inline.
|
||||
* @see IntermediateNodesAreInline
|
||||
*
|
||||
* @param aStartNode The left node, can be either a text node or a container node.
|
||||
* @param aStartOffset The start offset in the content of aStartNode
|
||||
* @param aEndNode The right node, can be either a text node or a container node.
|
||||
* @param aEndOffset The end offset in the content of aEndNode.
|
||||
* @param aGrandParentNode The common ancestor of aStartNode and aEndNode.
|
||||
* aGrandParentNode will be the parent of aNewParentNode.
|
||||
* @param aNewParentNode The node that will be the repositioned contents' parent.
|
||||
* The caller is responsible for allocating aNewParentNode
|
||||
*/
|
||||
NS_IMETHOD MoveContiguousContentIntoNewParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aGrandParentNode,
|
||||
nsIDOMNode *aNewParentNode);
|
||||
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNodeWithDifferentParents(nsIDOMRange *aRange,
|
||||
nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNodeWithDifferentParents(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD SetTypeInStateForProperty(TypeInState &aTypeInState,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
void GetTextSelectionOffsetsForRange(nsIDOMSelection *aSelection,
|
||||
nsIDOMNode **aParent,
|
||||
PRInt32 &aStartOffset,
|
||||
PRInt32 &aEndOffset);
|
||||
|
||||
void ResetTextSelectionForRange(nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMSelection *aSelection);
|
||||
|
||||
/** returns the absolute position of the end points of aSelection
|
||||
* in the document as a text stream.
|
||||
*/
|
||||
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
||||
PRInt32 &aStartOffset,
|
||||
PRInt32 &aEndOffset);
|
||||
|
||||
// Methods for handling plaintext quotations
|
||||
NS_IMETHOD PasteAsPlaintextQuotation();
|
||||
NS_IMETHOD InsertAsPlaintextQuotation(const nsString& aQuotedText);
|
||||
|
||||
// I hate seeing nsCOMPtr return types.
|
||||
nsCOMPtr<nsIDOMElement> FindPreElement();
|
||||
|
||||
TypeInState *GetTypeInState();
|
||||
|
||||
/** simple utility to handle any error with event listener allocation or registration */
|
||||
void HandleEventListenerError();
|
||||
|
||||
// Data members
|
||||
protected:
|
||||
|
||||
TypeInState* mTypeInState;
|
||||
nsEditRules* mRules;
|
||||
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mTextListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mCompositionListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
|
||||
PRBool mIsComposing;
|
||||
PRInt32 mMaxTextLength;
|
||||
PRUint32 mWrapColumn;
|
||||
|
||||
// friends
|
||||
friend class nsHTMLEditRules;
|
||||
friend class nsTextEditRules;
|
||||
|
||||
};
|
||||
|
||||
#endif //nsHTMLEditor_h__
|
||||
|
||||
132
mozilla/editor/base/nsIEditProperty.h
Normal file
132
mozilla/editor/base/nsIEditProperty.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsIEditProperty_h__
|
||||
#define __nsIEditProperty_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIAtom;
|
||||
class nsString;
|
||||
|
||||
#define NS_IEDITPROPERTY_IID \
|
||||
{/* 9875cd40-ca81-11d2-8f4d-006008159b0c*/ \
|
||||
0x9875cd40, 0xca81, 0x11d2, \
|
||||
{0x8f, 0x4d, 0x0, 0x60, 0x8, 0x15, 0x9b, 0x0c} }
|
||||
|
||||
/** simple interface for describing a single property as it relates to a range of content.
|
||||
*
|
||||
*/
|
||||
|
||||
class nsIEditProperty : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IEDITPROPERTY_IID; return iid; }
|
||||
|
||||
public:
|
||||
|
||||
/* we're still trying to decide how edit atoms will work. Until then, use these */
|
||||
// XXX: fix ASAP!
|
||||
// inline tags
|
||||
static nsIAtom *b;
|
||||
static nsIAtom *big;
|
||||
static nsIAtom *i;
|
||||
static nsIAtom *small;
|
||||
static nsIAtom *strike;
|
||||
static nsIAtom *sub;
|
||||
static nsIAtom *sup;
|
||||
static nsIAtom *tt;
|
||||
static nsIAtom *u;
|
||||
static nsIAtom *em;
|
||||
static nsIAtom *strong;
|
||||
static nsIAtom *dfn;
|
||||
static nsIAtom *code;
|
||||
static nsIAtom *samp;
|
||||
static nsIAtom *kbd;
|
||||
static nsIAtom *var;
|
||||
static nsIAtom *cite;
|
||||
static nsIAtom *abbr;
|
||||
static nsIAtom *acronym;
|
||||
static nsIAtom *font;
|
||||
static nsIAtom *a;
|
||||
static nsIAtom *img;
|
||||
static nsIAtom *object;
|
||||
static nsIAtom *br;
|
||||
static nsIAtom *script;
|
||||
static nsIAtom *map;
|
||||
static nsIAtom *q;
|
||||
static nsIAtom *span;
|
||||
static nsIAtom *bdo;
|
||||
static nsIAtom *input;
|
||||
static nsIAtom *select;
|
||||
static nsIAtom *textarea;
|
||||
static nsIAtom *label;
|
||||
static nsIAtom *button;
|
||||
// Block tags
|
||||
static nsIAtom *p;
|
||||
static nsIAtom *div;
|
||||
static nsIAtom *blockquote;
|
||||
static nsIAtom *h1;
|
||||
static nsIAtom *h2;
|
||||
static nsIAtom *h3;
|
||||
static nsIAtom *h4;
|
||||
static nsIAtom *h5;
|
||||
static nsIAtom *h6;
|
||||
static nsIAtom *ul;
|
||||
static nsIAtom *ol;
|
||||
static nsIAtom *dl;
|
||||
static nsIAtom *pre;
|
||||
static nsIAtom *noscript;
|
||||
static nsIAtom *form;
|
||||
static nsIAtom *hr;
|
||||
static nsIAtom *table;
|
||||
static nsIAtom *fieldset;
|
||||
static nsIAtom *address;
|
||||
// Assumed to be block:
|
||||
static nsIAtom *body;
|
||||
static nsIAtom *tr;
|
||||
static nsIAtom *td;
|
||||
static nsIAtom *th;
|
||||
static nsIAtom *caption;
|
||||
static nsIAtom *col;
|
||||
static nsIAtom *colgroup;
|
||||
static nsIAtom *thead;
|
||||
static nsIAtom *tfoot;
|
||||
static nsIAtom *li;
|
||||
static nsIAtom *dt;
|
||||
static nsIAtom *dd;
|
||||
static nsIAtom *legend;
|
||||
|
||||
/** properties **/
|
||||
static nsIAtom *color;
|
||||
static nsIAtom *face;
|
||||
static nsIAtom *size;
|
||||
|
||||
/** special strings */
|
||||
static nsString *allProperties; // this magic string represents the union of all inline style tags
|
||||
|
||||
// XXX: end temp code
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern nsresult NS_NewEditProperty(nsIEditProperty **aResult);
|
||||
|
||||
#endif
|
||||
76
mozilla/editor/base/nsIEditorSupport.h
Normal file
76
mozilla/editor/base/nsIEditorSupport.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIEditorSupport_h__
|
||||
#define nsIEditorSupport_h__
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIDOMNode;
|
||||
|
||||
/*
|
||||
Private Editor interface for a class that can provide helper functions
|
||||
*/
|
||||
|
||||
#define NS_IEDITORSUPPORT_IID \
|
||||
{/* 89b999b0-c529-11d2-86da-000064657374*/ \
|
||||
0x89b999b0, 0xc529, 0x11d2, \
|
||||
{0x86, 0xda, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
class nsIEditorSupport : public nsISupports {
|
||||
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IEDITORSUPPORT_IID; return iid; }
|
||||
|
||||
/**
|
||||
* SplitNode() creates a new node identical to an existing node, and split the contents between the two nodes
|
||||
* @param aExistingRightNode the node to split. It will become the new node's next sibling.
|
||||
* @param aOffset the offset of aExistingRightNode's content|children to do the split at
|
||||
* @param aNewLeftNode [OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
|
||||
* @param aParent the parent of aExistingRightNode
|
||||
*/
|
||||
NS_IMETHOD SplitNodeImpl(nsIDOMNode * aExistingRightNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMNode * aNewLeftNode,
|
||||
nsIDOMNode * aParent)=0;
|
||||
|
||||
/**
|
||||
* JoinNodes() takes 2 nodes and merge their content|children.
|
||||
* @param aNodeToKeep The node that will remain after the join.
|
||||
* @param aNodeToJoin The node that will be joined with aNodeToKeep.
|
||||
* There is no requirement that the two nodes be of the same type.
|
||||
* @param aParent The parent of aExistingRightNode
|
||||
* @param aNodeToKeepIsFirst if PR_TRUE, the contents|children of aNodeToKeep come before the
|
||||
* contents|children of aNodeToJoin, otherwise their positions are switched.
|
||||
*/
|
||||
NS_IMETHOD JoinNodesImpl(nsIDOMNode *aNodeToKeep,
|
||||
nsIDOMNode *aNodeToJoin,
|
||||
nsIDOMNode *aParent,
|
||||
PRBool aNodeToKeepIsFirst)=0;
|
||||
|
||||
static nsresult GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //nsIEditorSupport_h__
|
||||
|
||||
124
mozilla/editor/base/nsInsertHTMLTxn.cpp
Normal file
124
mozilla/editor/base/nsInsertHTMLTxn.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
// THIS FILE IS CURRENTLY THOUGHT TO BE OBSOLETE.
|
||||
// KEEPING AROUND FOR A FEW DAYS JUST TO MAKE SURE;
|
||||
// BUT IT'S NO LONGER PART OF THE BUILD.
|
||||
|
||||
#include "nsIDOMDocumentFragment.h"
|
||||
#include "nsInsertHTMLTxn.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMNSRange.h"
|
||||
|
||||
|
||||
nsInsertHTMLTxn::nsInsertHTMLTxn() : EditTxn(), mSrc("")
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Init(const nsString& aSrc, nsIEditor* aEditor)
|
||||
{
|
||||
if (!aEditor)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mSrc = aSrc;
|
||||
mEditor = do_QueryInterface(aEditor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsInsertHTMLTxn::~nsInsertHTMLTxn()
|
||||
{
|
||||
//NS_RELEASE(mStr); // do nsStrings have to be released?
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Do(void)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult res = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res) && selection)
|
||||
{
|
||||
// Get the first range in the selection, and save it in mRange:
|
||||
res = selection->GetRangeAt(0, getter_AddRefs(mRange));
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(mRange));
|
||||
if (nsrange)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
char* str = mSrc.ToNewCString();
|
||||
printf("Calling nsInsertHTMLTxn::Do(%s)\n", str);
|
||||
delete[] str;
|
||||
#endif /* DEBUG_akkana */
|
||||
nsCOMPtr<nsIDOMDocumentFragment> docfrag;
|
||||
res = nsrange->CreateContextualFragment(mSrc, getter_AddRefs(docfrag));
|
||||
|
||||
// Now we have to insert that document fragment in an undoable way
|
||||
printf("Sorry, Insert HTML not fully written yet\n");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_akkana
|
||||
else printf("nsInsertHTMLTxn::Do: Couldn't get selection range!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Undo(void)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("%p Undo Insert HTML\n", this);
|
||||
#endif /* DEBUG_akkana */
|
||||
|
||||
if (!mRange)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return mRange->DeleteContents();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull != aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove HTML: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert HTML: ";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
82
mozilla/editor/base/nsInsertHTMLTxn.h
Normal file
82
mozilla/editor/base/nsInsertHTMLTxn.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInsertHTMLTxn_h__
|
||||
#define nsInsertHTMLTxn_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_INSERT_HTML_TXN_CID \
|
||||
{/* a6cf90fd-15b3-11d2-932e-00805f8add3 */ \
|
||||
0xa6cf90fc, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
/**
|
||||
* A transaction that inserts a string of html source
|
||||
*/
|
||||
class nsInsertHTMLTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = NS_INSERT_HTML_TXN_CID; return iid; }
|
||||
|
||||
/** initialize the transaction.
|
||||
* @param aSrc the source for the HTML to insert
|
||||
* @param aEditor the editor in which to do the work
|
||||
*/
|
||||
NS_IMETHOD Init(const nsString& aSrc,
|
||||
nsIEditor *aEditor);
|
||||
|
||||
private:
|
||||
nsInsertHTMLTxn();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~nsInsertHTMLTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
/** the html to insert */
|
||||
nsString mSrc;
|
||||
|
||||
/** the range representing the inserted fragment */
|
||||
nsCOMPtr<nsIDOMRange> mRange;
|
||||
|
||||
/** the editor for this transaction */
|
||||
nsCOMPtr<nsIEditor> mEditor;
|
||||
|
||||
friend class TransactionFactory;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
300
mozilla/editor/base/nsInterfaceState.cpp
Normal file
300
mozilla/editor/base/nsInterfaceState.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDiskDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
#include "nsInterfaceState.h"
|
||||
|
||||
|
||||
|
||||
nsInterfaceState::nsInterfaceState()
|
||||
: mEditor(nsnull)
|
||||
, mWebShell(nsnull)
|
||||
, mBoldState(eStateUninitialized)
|
||||
, mItalicState(eStateUninitialized)
|
||||
, mUnderlineState(eStateUninitialized)
|
||||
, mDirtyState(eStateUninitialized)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsInterfaceState::~nsInterfaceState()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsInterfaceState);
|
||||
NS_IMPL_RELEASE(nsInterfaceState);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = nsnull;
|
||||
if (aIID.Equals(nsIDOMSelectionListener::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsIDOMSelectionListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsIDocumentStateListener::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsIDocumentStateListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsISupports *)(nsIDOMSelectionListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::Init(nsIHighLevelHTMLEditor* aEditor, nsIWebShell *aChromeWebShell)
|
||||
{
|
||||
if (!aEditor)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!aChromeWebShell)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
mEditor = aEditor; // no addreffing here
|
||||
mWebShell = aChromeWebShell;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentCreated()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentWillBeDestroyed()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentStateChanged(PRBool aNowDirty)
|
||||
{
|
||||
// update document modified. We should have some other notifications for this too.
|
||||
return UpdateDirtyState(aNowDirty);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifySelectionChanged()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// we don't really care if any of these fail.
|
||||
|
||||
// update bold
|
||||
rv = UpdateTextState("b", "Editor:Style:IsBold", "bold", mBoldState);
|
||||
// update italic
|
||||
rv = UpdateTextState("i", "Editor:Style:IsItalic", "italic", mItalicState);
|
||||
// update underline
|
||||
rv = UpdateTextState("u", "Editor:Style:IsUnderline", "underline", mUnderlineState);
|
||||
|
||||
// udpate the font face
|
||||
rv = UpdateFontFace("Editor:Font:Face", "font", mFontString);
|
||||
|
||||
// update the paragraph format popup
|
||||
rv = UpdateParagraphState("Editor:Paragraph:Format", "format", mParagraphFormat);
|
||||
|
||||
// update the list buttons
|
||||
rv = UpdateListState("Editor:Paragraph:List", "ol");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat)
|
||||
{
|
||||
nsStringArray tagList;
|
||||
|
||||
mEditor->GetParagraphStyle(&tagList);
|
||||
|
||||
PRInt32 numTags = tagList.Count();
|
||||
if (numTags > 0)
|
||||
{
|
||||
nsAutoString thisTag;
|
||||
tagList.StringAt(0, thisTag);
|
||||
if (thisTag != mParagraphFormat)
|
||||
{
|
||||
nsresult rv = SetNodeAttribute(observerName, attributeName, thisTag);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mParagraphFormat = thisTag;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateListState(const char* observerName, const char* tagName)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> domSelection;
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
editor->GetSelection(getter_AddRefs(domSelection));
|
||||
}
|
||||
|
||||
nsAutoString tagStr(tagName);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
if (domSelection)
|
||||
domSelection->GetAnchorNode(getter_AddRefs(domNode));
|
||||
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
rv = mEditor->GetElementOrParentByTagName(tagStr, domNode, getter_AddRefs(parentElement));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateFontFace(const char* observerName, const char* attributeName, nsString& ioFontString)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
nsAutoString faceStr("face");
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(tagName));
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
PRBool &behaviour = allOfSelectionHasProp; // change this to alter the behaviour
|
||||
if (behaviour != ioState)
|
||||
{
|
||||
rv = SetNodeAttribute(observerName, attributeName, behaviour ? "true" : "false");
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
ioState = behaviour;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
|
||||
{
|
||||
if (mDirtyState != aNowDirty)
|
||||
{
|
||||
nsresult rv = SetNodeAttribute("Editor:Document:Dirty", "dirty", aNowDirty ? "true" : "false");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mDirtyState = aNowDirty;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!mWebShell)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = mWebShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocument> chromeDoc;
|
||||
rv = docViewer->GetDocument(*getter_AddRefs(chromeDoc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(chromeDoc, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = xulDoc->GetElementById( nodeID, getter_AddRefs(elem) );
|
||||
if (NS_FAILED(rv) || !elem) return rv;
|
||||
|
||||
return elem->SetAttribute(attributeName, newValue);
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_NewInterfaceState(nsIHighLevelHTMLEditor* aEditor, nsIWebShell* aWebShell, nsIDOMSelectionListener** aInstancePtrResult)
|
||||
{
|
||||
nsInterfaceState* newThang = new nsInterfaceState;
|
||||
if (!newThang)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aInstancePtrResult = nsnull;
|
||||
nsresult rv = newThang->Init(aEditor, aWebShell);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete newThang;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return newThang->QueryInterface(nsIDOMSelectionListener::GetIID(), (void **)aInstancePtrResult);
|
||||
}
|
||||
90
mozilla/editor/base/nsInterfaceState.h
Normal file
90
mozilla/editor/base/nsInterfaceState.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsInterfaceState_h__
|
||||
#define nsInterfaceState_h__
|
||||
|
||||
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#include "nsIDocumentStateListener.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
class nsIHighLevelHTMLEditor;
|
||||
|
||||
// class responsible for communicating changes in local state back to the UI.
|
||||
// This is currently somewhat tied to a given XUL UI implementation
|
||||
|
||||
class nsInterfaceState : public nsIDOMSelectionListener,
|
||||
public nsIDocumentStateListener
|
||||
{
|
||||
public:
|
||||
|
||||
nsInterfaceState();
|
||||
virtual ~nsInterfaceState();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(nsIHighLevelHTMLEditor* aEditor, nsIWebShell *aChromeWebShell);
|
||||
|
||||
// nsIDOMSelectionListener interface
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
// nsIDocumentStateListener interface
|
||||
NS_IMETHOD NotifyDocumentCreated();
|
||||
NS_IMETHOD NotifyDocumentWillBeDestroyed();
|
||||
NS_IMETHOD NotifyDocumentStateChanged(PRBool aNowDirty);
|
||||
|
||||
protected:
|
||||
|
||||
enum {
|
||||
eStateUninitialized = -1,
|
||||
eStateOff = PR_FALSE,
|
||||
eStateOn = PR_TRUE
|
||||
};
|
||||
|
||||
nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue);
|
||||
|
||||
nsresult UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat);
|
||||
nsresult UpdateListState(const char* observerName, const char* tagName);
|
||||
nsresult UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState);
|
||||
nsresult UpdateFontFace(const char* observerName, const char* attributeName, nsString& ioFontString);
|
||||
nsresult UpdateDirtyState(PRBool aNowDirty);
|
||||
|
||||
// this class should not hold references to the editor or editorShell. Doing
|
||||
// so would result in cirular reference chains.
|
||||
|
||||
nsIHighLevelHTMLEditor* mEditor; // the HTML editor
|
||||
nsIWebShell* mWebShell; // web shell for the chrome area
|
||||
|
||||
// current state
|
||||
PRInt8 mBoldState;
|
||||
PRInt8 mItalicState;
|
||||
PRInt8 mUnderlineState;
|
||||
|
||||
PRInt8 mDirtyState;
|
||||
|
||||
nsString mParagraphFormat;
|
||||
nsString mFontString;
|
||||
nsString mListTag; // contains "" for none, "ol" or "ul"
|
||||
|
||||
};
|
||||
|
||||
extern "C" nsresult NS_NewInterfaceState(nsIHighLevelHTMLEditor* aEditor, nsIWebShell* aWebShell, nsIDOMSelectionListener** aInstancePtrResult);
|
||||
|
||||
#endif // nsInterfaceState_h__
|
||||
86
mozilla/editor/base/nsInternetCiter.cpp
Normal file
86
mozilla/editor/base/nsInternetCiter.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsInternetCiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the Internet style >> This is a citation <<
|
||||
*/
|
||||
|
||||
nsInternetCiter::nsInternetCiter()
|
||||
{
|
||||
}
|
||||
|
||||
nsInternetCiter::~nsInternetCiter()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsInternetCiter)
|
||||
|
||||
NS_IMPL_RELEASE(nsInternetCiter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsICiter::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsICiter*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
PRUnichar newline ('\n');
|
||||
PRInt32 i = 0;
|
||||
PRInt32 length = aInString.Length();
|
||||
aOutString = "\n\n";
|
||||
PRUnichar uch = newline;
|
||||
|
||||
// Loop over the string:
|
||||
while (i < length)
|
||||
{
|
||||
if (uch == newline)
|
||||
aOutString += "> ";
|
||||
|
||||
uch = aInString[i++];
|
||||
aOutString += uch;
|
||||
}
|
||||
|
||||
if (uch != newline)
|
||||
aOutString += newline;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
mozilla/editor/base/nsInternetCiter.h
Normal file
41
mozilla/editor/base/nsInternetCiter.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInternetCiter_h__
|
||||
#define nsInternetCiter_h__
|
||||
|
||||
#include "nsICiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
*/
|
||||
class nsInternetCiter : public nsICiter
|
||||
{
|
||||
public:
|
||||
nsInternetCiter();
|
||||
virtual ~nsInternetCiter();
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetCiteString(const nsString& aInString, nsString& aOutString);
|
||||
};
|
||||
|
||||
#endif //nsInternetCiter_h__
|
||||
|
||||
1412
mozilla/editor/base/nsJSEditorLog.cpp
Normal file
1412
mozilla/editor/base/nsJSEditorLog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
189
mozilla/editor/base/nsJSEditorLog.h
Normal file
189
mozilla/editor/base/nsJSEditorLog.h
Normal file
@@ -0,0 +1,189 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsJSEditorLog_h__
|
||||
#define nsJSEditorLog_h__
|
||||
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
/** implementation of a transaction listener object.
|
||||
*
|
||||
*/
|
||||
class nsJSEditorLog : public nsIHTMLEditor
|
||||
{
|
||||
private:
|
||||
|
||||
nsCOMPtr<nsIFileSpec> mFileSpec;
|
||||
nsIEditor *mEditor;
|
||||
PRInt32 mLocked;
|
||||
PRInt32 mDepth;
|
||||
|
||||
public:
|
||||
|
||||
/** The default constructor.
|
||||
*/
|
||||
nsJSEditorLog(nsIEditor *aEditor, nsIFileSpec *aLogFile);
|
||||
|
||||
/** The default destructor.
|
||||
*/
|
||||
virtual ~nsJSEditorLog();
|
||||
|
||||
/* Macro for AddRef(), Release(), and QueryInterface() */
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* nsIHTMLEditor method implementations. */
|
||||
NS_IMETHOD Init(nsIDOMDocument *aDoc,
|
||||
nsIPresShell *aPresShell);
|
||||
NS_IMETHOD SetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
NS_IMETHOD GetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAll, PRBool &aAny);
|
||||
NS_IMETHOD GetParagraphFormat(nsString& aParagraphFormat);
|
||||
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
|
||||
NS_IMETHOD RemoveTextProperty(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
NS_IMETHOD DeleteSelection(nsIEditor::ESelectionCollapseDirection aAction);
|
||||
NS_IMETHOD InsertText(const nsString& aStringToInsert);
|
||||
NS_IMETHOD InsertBreak();
|
||||
NS_IMETHOD EnableUndo(PRBool aEnable);
|
||||
NS_IMETHOD Undo(PRUint32 aCount);
|
||||
NS_IMETHOD CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
NS_IMETHOD Redo(PRUint32 aCount);
|
||||
NS_IMETHOD CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
NS_IMETHOD BeginTransaction();
|
||||
NS_IMETHOD EndTransaction();
|
||||
NS_IMETHOD MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD BeginningOfDocument();
|
||||
NS_IMETHOD EndOfDocument();
|
||||
NS_IMETHOD ScrollUp(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollDown(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
|
||||
|
||||
NS_IMETHOD Save();
|
||||
NS_IMETHOD SaveAs(PRBool aSavingCopy);
|
||||
|
||||
NS_IMETHOD Cut();
|
||||
NS_IMETHOD Copy();
|
||||
NS_IMETHOD Paste();
|
||||
NS_IMETHOD PasteAsQuotation();
|
||||
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation);
|
||||
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
|
||||
NS_IMETHOD InsertAsCitedQuotation(const nsString& aQuotedText, const nsString& aCitation);
|
||||
|
||||
|
||||
NS_IMETHOD InsertHTML(const nsString &aInputString);
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||
|
||||
NS_IMETHOD GetLocalFileURL(nsIDOMWindow* aParent, const nsString& aFilterType, nsString& aReturn);
|
||||
NS_IMETHOD SetBackgroundColor(const nsString& aColor);
|
||||
NS_IMETHOD SetBodyAttribute(const nsString& aAttr, const nsString& aValue);
|
||||
NS_IMETHOD GetParagraphStyle(nsStringArray *aTagList);
|
||||
NS_IMETHOD AddBlockParent(nsString& aParentTag);
|
||||
NS_IMETHOD ReplaceBlockParent(nsString& aParentTag);
|
||||
NS_IMETHOD RemoveParagraphStyle();
|
||||
NS_IMETHOD RemoveParent(const nsString &aParentTag);
|
||||
NS_IMETHOD InsertList(const nsString& aListType);
|
||||
NS_IMETHOD Indent(const nsString& aIndent);
|
||||
NS_IMETHOD Align(const nsString& aAlign);
|
||||
NS_IMETHOD GetElementOrParentByTagName(const nsString& aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn);
|
||||
NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn);
|
||||
NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn);
|
||||
NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection);
|
||||
NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement);
|
||||
NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement);
|
||||
NS_IMETHOD SelectElement(nsIDOMElement* aElement);
|
||||
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement);
|
||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList);
|
||||
NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32 &aColIndex, PRInt32 &aRowIndex);
|
||||
NS_IMETHOD GetTableSize(nsIDOMElement *aTable, PRInt32 &aRowCount, PRInt32 &aColCount);
|
||||
NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell);
|
||||
NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement* &aCell,
|
||||
PRInt32& aStartRowIndex, PRInt32& aStartColIndex, PRInt32& aRowSpan, PRInt32& aColSpan, PRBool& aIsSelected);
|
||||
NS_IMETHOD InsertTable();
|
||||
NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD InsertTableRow(PRInt32 aNumber, PRBool aAfter);
|
||||
NS_IMETHOD DeleteTable();
|
||||
NS_IMETHOD DeleteTableCell(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
|
||||
NS_IMETHOD JoinTableCells();
|
||||
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
|
||||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRangeList);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
|
||||
NS_IMETHOD StopLogging();
|
||||
|
||||
/* nsJSEditorLog public methods. */
|
||||
nsresult Write(const char *aBuffer);
|
||||
nsresult WriteInt(const char *aFormat, PRInt32 aInt);
|
||||
nsresult Flush();
|
||||
nsresult PrintUnicode(const nsString &aString);
|
||||
nsresult PrintSelection();
|
||||
nsresult PrintNode(nsIDOMNode *aNode, PRInt32 aDepth=0);
|
||||
nsresult PrintElementNode(nsIDOMNode *aNode, PRInt32 aDepth);
|
||||
nsresult PrintTextNode(nsIDOMNode *aNode, PRInt32 aDepth);
|
||||
nsresult PrintAttributeNode(nsIDOMNode *aNode, PRInt32 aDepth=0);
|
||||
nsresult PrintNodeChildren(nsIDOMNode *aNode, PRInt32 aDepth=0);
|
||||
nsresult GetNodeTreeOffsets(nsIDOMNode *aNode, PRInt32 **aResult, PRInt32 *aLength);
|
||||
nsresult Lock();
|
||||
nsresult Unlock();
|
||||
};
|
||||
|
||||
class nsAutoJSEditorLogLock
|
||||
{
|
||||
nsJSEditorLog *mLog;
|
||||
|
||||
public:
|
||||
|
||||
nsAutoJSEditorLogLock(nsJSEditorLog *aLog)
|
||||
{
|
||||
mLog = aLog;
|
||||
|
||||
if (mLog)
|
||||
mLog->Lock();
|
||||
}
|
||||
|
||||
~nsAutoJSEditorLogLock()
|
||||
{
|
||||
if (mLog)
|
||||
mLog->Unlock();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // nsJSEditorLog_h__
|
||||
406
mozilla/editor/base/nsJSTxnLog.cpp
Normal file
406
mozilla/editor/base/nsJSTxnLog.cpp
Normal file
@@ -0,0 +1,406 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsJSEditorLog.h"
|
||||
#include "nsJSTxnLog.h"
|
||||
|
||||
#define LOCK_LOG(doc)
|
||||
#define UNLOCK_LOG(doc)
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
nsJSTxnLog::nsJSTxnLog(nsJSEditorLog *aEditorLog)
|
||||
{
|
||||
mRefCnt = 0;
|
||||
mIndentLevel = 0;
|
||||
mBatchCount = 0;
|
||||
mEditorLog = aEditorLog;
|
||||
}
|
||||
|
||||
nsJSTxnLog::~nsJSTxnLog()
|
||||
{
|
||||
}
|
||||
|
||||
#define DEBUG_JS_TXN_LOG_REFCNT 1
|
||||
|
||||
#ifdef DEBUG_JS_TXN_LOG_REFCNT
|
||||
|
||||
nsrefcnt nsJSTxnLog::AddRef(void)
|
||||
{
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt nsJSTxnLog::Release(void)
|
||||
{
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
if (--mRefCnt == 0) {
|
||||
NS_DELETEXPCOM(this);
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
NS_IMPL_ADDREF(nsJSTxnLog)
|
||||
NS_IMPL_RELEASE(nsJSTxnLog)
|
||||
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsITransactionListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsITransactionListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
*aInstancePtr = 0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel++);
|
||||
Write("WillDo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aDoResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(--mIndentLevel);
|
||||
Write("DidDo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("(");
|
||||
WriteInt("%d", aDoResult);
|
||||
Write(")\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel++);
|
||||
|
||||
if (aTransaction)
|
||||
{
|
||||
Write("WillUndo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("\n");
|
||||
}
|
||||
else
|
||||
Write("WillUndoBatch\n");
|
||||
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aUndoResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(--mIndentLevel);
|
||||
|
||||
if (aTransaction)
|
||||
{
|
||||
Write("DidUndo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("(");
|
||||
WriteInt("%d", aUndoResult);
|
||||
Write(")\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Write("EndUndoBatch (");
|
||||
WriteInt("%d", aUndoResult);
|
||||
Write(")\n");
|
||||
}
|
||||
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel++);
|
||||
|
||||
if (aTransaction)
|
||||
{
|
||||
Write("WillRedo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("\n");
|
||||
}
|
||||
else
|
||||
Write("WillRedoBatch\n");
|
||||
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aRedoResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(--mIndentLevel);
|
||||
|
||||
if (aTransaction)
|
||||
{
|
||||
Write("DidRedo: ");
|
||||
Write(GetString(aTransaction));
|
||||
Write(" (");
|
||||
WriteInt("%d", aRedoResult);
|
||||
Write(")\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Write("DidRedoBatch (");
|
||||
WriteInt("%d", aRedoResult);
|
||||
Write(")\n");
|
||||
}
|
||||
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillBeginBatch(nsITransactionManager *aTxMgr)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel);
|
||||
Write("WillBeginBatch: ");
|
||||
WriteInt("%d", mBatchCount);
|
||||
Write("\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidBeginBatch(nsITransactionManager *aTxMgr, nsresult aResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel++);
|
||||
Write("DidBeginBatch: ");
|
||||
WriteInt("%d", mBatchCount++);
|
||||
Write(" (");
|
||||
WriteInt("%d", aResult);
|
||||
Write(")\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillEndBatch(nsITransactionManager *aTxMgr)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(--mIndentLevel);
|
||||
Write("WillEndBatch: ");
|
||||
WriteInt("%d", --mBatchCount);
|
||||
Write("\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidEndBatch(nsITransactionManager *aTxMgr, nsresult aResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel);
|
||||
Write("DidEndBatch: ");
|
||||
WriteInt("%d", mBatchCount);
|
||||
Write(" (");
|
||||
WriteInt("%d", aResult);
|
||||
Write(")\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel);
|
||||
Write("WillMerge: ");
|
||||
Write(GetString(aTopTransaction));
|
||||
Write(" <-- ");
|
||||
Write(GetString(aTransaction));
|
||||
Write("\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, PRBool aDidMerge, nsresult aMergeResult)
|
||||
{
|
||||
LOCK_LOG(this);
|
||||
|
||||
PrintIndent(mIndentLevel);
|
||||
Write("DidMerge: ");
|
||||
Write(GetString(aTopTransaction));
|
||||
Write(" <-- ");
|
||||
Write(GetString(aTransaction));
|
||||
Write(" (");
|
||||
Write(aDidMerge ? "TRUE" : "FALSE");
|
||||
Write(", ");
|
||||
WriteInt("%d", aMergeResult);
|
||||
Write(")\n");
|
||||
Flush();
|
||||
|
||||
UNLOCK_LOG(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const char *
|
||||
nsJSTxnLog::GetString(nsITransaction *aTransaction)
|
||||
{
|
||||
static char buf[256];
|
||||
|
||||
nsString str = "";
|
||||
|
||||
aTransaction->GetRedoString(&str);
|
||||
|
||||
if (str.Length() == 0)
|
||||
str = "<NULL>";
|
||||
|
||||
buf[0] = '\0';
|
||||
str.ToCString(buf, 256);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSTxnLog::PrintIndent(PRInt32 aIndentLevel)
|
||||
{
|
||||
PRInt32 i;
|
||||
|
||||
Write(" // ");
|
||||
|
||||
for (i = 0; i < aIndentLevel; i++)
|
||||
Write(" ");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSTxnLog::Write(const char *aBuffer)
|
||||
{
|
||||
if (!aBuffer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mEditorLog)
|
||||
mEditorLog->Write(aBuffer);
|
||||
else
|
||||
printf(aBuffer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSTxnLog::WriteInt(const char *aFormat, PRInt32 aInt)
|
||||
{
|
||||
if (!aFormat)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mEditorLog)
|
||||
mEditorLog->WriteInt(aFormat, aInt);
|
||||
else
|
||||
printf(aFormat, aInt);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSTxnLog::Flush()
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
#ifdef SLOWS_THINGS_WAY_DOWN
|
||||
|
||||
if (mEditorLog)
|
||||
result = mEditorLog->Flush();
|
||||
else
|
||||
fflush(stdout);
|
||||
|
||||
#endif // SLOWS_THINGS_WAY_DOWN
|
||||
|
||||
return result;
|
||||
}
|
||||
77
mozilla/editor/base/nsJSTxnLog.h
Normal file
77
mozilla/editor/base/nsJSTxnLog.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsJSTxnLog_h__
|
||||
#define nsJSTxnLog_h__
|
||||
|
||||
#include "nsITransaction.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "nsITransactionListener.h"
|
||||
|
||||
class nsJSEditorLog;
|
||||
|
||||
/** implementation of a transaction listener object.
|
||||
*
|
||||
*/
|
||||
class nsJSTxnLog : public nsITransactionListener
|
||||
{
|
||||
private:
|
||||
|
||||
nsJSEditorLog *mEditorLog;
|
||||
PRInt32 mIndentLevel;
|
||||
PRInt32 mBatchCount;
|
||||
|
||||
public:
|
||||
|
||||
/** The default constructor.
|
||||
*/
|
||||
nsJSTxnLog(nsJSEditorLog *aEditorLog=0);
|
||||
|
||||
/** The default destructor.
|
||||
*/
|
||||
virtual ~nsJSTxnLog();
|
||||
|
||||
/* Macro for AddRef(), Release(), and QueryInterface() */
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* nsITransactionListener method implementations. */
|
||||
NS_IMETHOD WillDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction);
|
||||
NS_IMETHOD DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aDoResult);
|
||||
NS_IMETHOD WillUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction);
|
||||
NS_IMETHOD DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aUndoResult);
|
||||
NS_IMETHOD WillRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction);
|
||||
NS_IMETHOD DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransaction, nsresult aRedoResult);
|
||||
NS_IMETHOD WillBeginBatch(nsITransactionManager *aTxMgr);
|
||||
NS_IMETHOD DidBeginBatch(nsITransactionManager *aTxMgr, nsresult aResult);
|
||||
NS_IMETHOD WillEndBatch(nsITransactionManager *aTxMgr);
|
||||
NS_IMETHOD DidEndBatch(nsITransactionManager *aTxMgr, nsresult aResult);
|
||||
NS_IMETHOD WillMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction);
|
||||
NS_IMETHOD DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTransaction, nsITransaction *aTransaction, PRBool aDidMerge, nsresult aMergeResult);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* nsJSTxnLog private methods. */
|
||||
const char *GetString(nsITransaction *aTransaction);
|
||||
nsresult PrintIndent(PRInt32 aIndentLevel);
|
||||
nsresult Write(const char *aBuffer);
|
||||
nsresult WriteInt(const char *aFormat, PRInt32 aInt);
|
||||
nsresult Flush();
|
||||
};
|
||||
|
||||
#endif // nsJSTxnLog_h__
|
||||
297
mozilla/editor/base/nsStyleSheetTxns.cpp
Normal file
297
mozilla/editor/base/nsStyleSheetTxns.cpp
Normal file
@@ -0,0 +1,297 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsEditor.h"
|
||||
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsIStyleSet.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
|
||||
|
||||
#include "nsStyleSheetTxns.h"
|
||||
|
||||
|
||||
|
||||
AddStyleSheetTxn::AddStyleSheetTxn()
|
||||
: mEditor(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AddStyleSheetTxn::~AddStyleSheetTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Init(nsIEditor *aEditor, nsICSSStyleSheet *aSheet)
|
||||
{
|
||||
if (!aEditor)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!aSheet)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
mEditor = aEditor;
|
||||
mSheet = do_QueryInterface(aSheet);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Do()
|
||||
{
|
||||
if (!mEditor || !mSheet)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
mEditor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (!presShell)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && styleSet)
|
||||
{
|
||||
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(mSheet);
|
||||
|
||||
if (styleSheet)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = presShell->GetDocument(getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && document)
|
||||
document->AddStyleSheet(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Undo()
|
||||
{
|
||||
if (!mEditor || !mSheet)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
mEditor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (!presShell)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && styleSet)
|
||||
{
|
||||
styleSet->RemoveDocStyleSheet(mSheet);
|
||||
|
||||
nsCOMPtr<nsIDocumentObserver> observer = do_QueryInterface(presShell);
|
||||
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(mSheet);
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
|
||||
rv = presShell->GetDocument(getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && document && observer && styleSheet)
|
||||
rv = observer->StyleSheetRemoved(document, styleSheet);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Redo()
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
if (!aDidMerge)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (aString)
|
||||
{
|
||||
*aString="Remove Style Sheet";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AddStyleSheetTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (aString)
|
||||
{
|
||||
*aString="Add Style Sheet";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
|
||||
RemoveStyleSheetTxn::RemoveStyleSheetTxn()
|
||||
: mEditor(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
RemoveStyleSheetTxn::~RemoveStyleSheetTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsICSSStyleSheet *aSheet)
|
||||
{
|
||||
if (!aEditor)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!aSheet)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
mEditor = aEditor;
|
||||
mSheet = do_QueryInterface(aSheet);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Do()
|
||||
{
|
||||
if (!mEditor || !mSheet)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
mEditor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (!presShell)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && styleSet)
|
||||
{
|
||||
styleSet->RemoveDocStyleSheet(mSheet);
|
||||
|
||||
nsCOMPtr<nsIDocumentObserver> observer = do_QueryInterface(presShell);
|
||||
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(mSheet);
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
|
||||
rv = presShell->GetDocument(getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && document && observer && styleSheet)
|
||||
rv = observer->StyleSheetRemoved(document, styleSheet);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Undo()
|
||||
{
|
||||
if (!mEditor || !mSheet)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
mEditor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (!presShell)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
nsresult rv = presShell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && styleSet)
|
||||
{
|
||||
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(mSheet);
|
||||
|
||||
if (styleSheet)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = presShell->GetDocument(getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && document)
|
||||
document->AddStyleSheet(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Redo()
|
||||
{
|
||||
return Do();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
if (!aDidMerge)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (aString)
|
||||
{
|
||||
*aString="Add Style Sheet";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoveStyleSheetTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (aString)
|
||||
{
|
||||
*aString="Remove Style Sheet";
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
124
mozilla/editor/base/nsStyleSheetTxns.h
Normal file
124
mozilla/editor/base/nsStyleSheetTxns.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsStylesheetTxns_h__
|
||||
#define nsStylesheetTxns_h__
|
||||
|
||||
#include "EditTxn.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
|
||||
#define ADD_STYLESHEET_TXN_CID \
|
||||
{/* d05e2980-2fbe-11d3-9ce4-e8393835307c */ \
|
||||
0xd05e2980, 0x2fbe, 0x11d3, { 0x9c, 0xe4, 0xe8, 0x39, 0x38, 0x35, 0x30, 0x7c } }
|
||||
|
||||
#define REMOVE_STYLESHEET_TXN_CID \
|
||||
{/* d05e2981-2fbe-11d3-9ce4-e8393835307c */ \
|
||||
0xd05e2981, 0x2fbe, 0x11d3, { 0x9c, 0xe4, 0xe8, 0x39, 0x38, 0x35, 0x30, 0x7c } }
|
||||
|
||||
|
||||
class AddStyleSheetTxn : public EditTxn
|
||||
{
|
||||
friend class TransactionFactory;
|
||||
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = ADD_STYLESHEET_TXN_CID; return iid; }
|
||||
|
||||
virtual ~AddStyleSheetTxn();
|
||||
|
||||
/** Initialize the transaction.
|
||||
* @param aEditor the object providing core editing operations
|
||||
* @param aSheet the stylesheet to add
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
nsICSSStyleSheet *aSheet);
|
||||
|
||||
private:
|
||||
AddStyleSheetTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
nsIEditor* mEditor; // the editor that created this transaction
|
||||
nsCOMPtr<nsICSSStyleSheet> mSheet; // the style sheet to add
|
||||
|
||||
};
|
||||
|
||||
|
||||
class RemoveStyleSheetTxn : public EditTxn
|
||||
{
|
||||
friend class TransactionFactory;
|
||||
|
||||
public:
|
||||
|
||||
static const nsIID& GetCID() { static nsIID iid = REMOVE_STYLESHEET_TXN_CID; return iid; }
|
||||
|
||||
virtual ~RemoveStyleSheetTxn();
|
||||
|
||||
/** Initialize the transaction.
|
||||
* @param aEditor the object providing core editing operations
|
||||
* @param aSheet the stylesheet to remove
|
||||
*/
|
||||
NS_IMETHOD Init(nsIEditor *aEditor,
|
||||
nsICSSStyleSheet *aSheet);
|
||||
|
||||
private:
|
||||
RemoveStyleSheetTxn();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void);
|
||||
|
||||
NS_IMETHOD Redo(void);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
protected:
|
||||
|
||||
nsIEditor* mEditor; // the editor that created this transaction
|
||||
nsCOMPtr<nsICSSStyleSheet> mSheet; // the style sheet to remove
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsStylesheetTxns_h__ */
|
||||
124
mozilla/editor/base/nsTextEditFactory.cpp
Normal file
124
mozilla/editor/base/nsTextEditFactory.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsTextEditFactory.h"
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsTextEditor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsEditorCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
|
||||
|
||||
nsresult
|
||||
GetTextEditFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
PR_EnterMonitor(GetEditorMonitor());
|
||||
|
||||
nsTextEditFactory *factory = new nsTextEditFactory(aClass);
|
||||
if (!factory)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
|
||||
if (!pNSIFactory)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(),
|
||||
(void **)aFactory);
|
||||
PR_ExitMonitor(GetEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports
|
||||
|
||||
nsresult
|
||||
nsTextEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
NS_NOTREACHED("!nsEditor");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIFactory::GetIID()) ||
|
||||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditFactory)
|
||||
NS_IMPL_RELEASE(nsTextEditFactory)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsISupports *obj = nsnull;
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aOuter && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
|
||||
|
||||
if (mCID.Equals(kTextEditorCID))
|
||||
{
|
||||
//Need to cast to interface first to avoid "ambiguous conversion..." error
|
||||
// because of multiple nsISupports in the class hierarchy
|
||||
obj = (nsISupports *)(nsITextEditor*)new nsTextEditor();
|
||||
}
|
||||
//more class ids to support. here
|
||||
|
||||
|
||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||
{
|
||||
delete obj;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsTextEditFactory:
|
||||
|
||||
nsTextEditFactory::nsTextEditFactory(const nsCID &aClass)
|
||||
:mCID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsTextEditFactory::~nsTextEditFactory()
|
||||
{
|
||||
//nsComponentManager::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
|
||||
}
|
||||
66
mozilla/editor/base/nsTextEditFactory.h
Normal file
66
mozilla/editor/base/nsTextEditFactory.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://wwwt.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsTextEditFactory_h___
|
||||
#define nsTextEditFactory_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
Factory that can make a text editor
|
||||
*/
|
||||
|
||||
/**
|
||||
* This supplies the neccessary entrance to the edit module. it will return any
|
||||
* instantiations that we need.
|
||||
*/
|
||||
class nsTextEditFactory;
|
||||
|
||||
extern nsresult GetTextEditFactory(nsIFactory **aFactory, const nsCID & aClass);
|
||||
|
||||
class nsTextEditFactory : public nsIFactory {
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports and AggregatedQueryInterface:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_IMETHOD
|
||||
CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD
|
||||
LockFactory(PRBool aLock);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual ~nsTextEditFactory(void);
|
||||
private:
|
||||
nsTextEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
|
||||
|
||||
/** GetTextEditFactory
|
||||
* creates an edit factory other CSID supported friend functions here.
|
||||
*/
|
||||
friend nsresult GetTextEditFactory(nsIFactory **, const nsCID & );
|
||||
const nsCID &mCID;
|
||||
};
|
||||
|
||||
#endif //nsIEditFactory_h___
|
||||
968
mozilla/editor/base/nsTextEditRules.cpp
Normal file
968
mozilla/editor/base/nsTextEditRules.cpp
Normal file
@@ -0,0 +1,968 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL") you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsTextEditRules.h"
|
||||
|
||||
#include "nsEditor.h"
|
||||
#include "PlaceholderTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsIEditProperty.h"
|
||||
|
||||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
|
||||
#define CANCEL_OPERATION_IF_READONLY_OR_DISABLED \
|
||||
if ((mFlags & nsIHighLevelHTMLEditor::eEditorReadonlyMask) || (mFlags & nsIHighLevelHTMLEditor::eEditorDisabledMask)) \
|
||||
{ \
|
||||
*aCancel = PR_TRUE; \
|
||||
return NS_OK; \
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
* Constructor/Destructor
|
||||
********************************************************/
|
||||
|
||||
nsTextEditRules::nsTextEditRules(PRUint32 aFlags)
|
||||
: mEditor(nsnull)
|
||||
, mFlags(aFlags)
|
||||
{
|
||||
}
|
||||
|
||||
nsTextEditRules::~nsTextEditRules()
|
||||
{
|
||||
// do NOT delete mEditor here. We do not hold a ref count to mEditor. mEditor owns our lifespan.
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
* Public methods
|
||||
********************************************************/
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::Init(nsHTMLEditor *aEditor)
|
||||
{
|
||||
if (!aEditor) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
mEditor = aEditor; // we hold a non-refcounted reference back to our editor
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ASSERTION(selection, "editor cannot get selection");
|
||||
nsresult result = CreateBogusNodeIfNeeded(selection); // this method handles null selection, which should never happen anyway
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::GetFlags(PRUint32 *aFlags)
|
||||
{
|
||||
if (!aFlags) { return NS_ERROR_NULL_POINTER; }
|
||||
*aFlags = mFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::SetFlags(PRUint32 aFlags)
|
||||
{
|
||||
if (mFlags == aFlags) return NS_OK;
|
||||
|
||||
// XXX - this won't work if body element already has
|
||||
// a style attribute on it, don't know why.
|
||||
// SetFlags() is really meant to only be called once
|
||||
// and at editor init time.
|
||||
if (aFlags & nsIHighLevelHTMLEditor::eEditorPlaintextMask)
|
||||
{
|
||||
if (!(mFlags & nsIHighLevelHTMLEditor::eEditorPlaintextMask))
|
||||
{
|
||||
// we are converting TO a plaintext editor
|
||||
// put a "white-space: pre" style on the body
|
||||
nsCOMPtr<nsIDOMElement> bodyElement;
|
||||
nsresult res = mEditor->GetBodyElement(getter_AddRefs(bodyElement));
|
||||
if (NS_SUCCEEDED(res) && bodyElement)
|
||||
{
|
||||
// not going through the editor to do this.
|
||||
bodyElement->SetAttribute("style", "white-space: pre");
|
||||
}
|
||||
}
|
||||
}
|
||||
mFlags = aFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::WillDoAction(nsIDOMSelection *aSelection,
|
||||
nsRulesInfo *aInfo, PRBool *aCancel)
|
||||
{
|
||||
// null selection is legal
|
||||
if (!aInfo || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
*aCancel = PR_FALSE;
|
||||
|
||||
// my kingdom for dynamic cast
|
||||
nsTextRulesInfo *info = NS_STATIC_CAST(nsTextRulesInfo*, aInfo);
|
||||
|
||||
switch (info->action)
|
||||
{
|
||||
case kInsertBreak:
|
||||
return WillInsertBreak(aSelection, aCancel);
|
||||
case kInsertText:
|
||||
return WillInsertText(aSelection,
|
||||
aCancel,
|
||||
info->placeTxn,
|
||||
info->inString,
|
||||
info->outString,
|
||||
info->typeInState,
|
||||
info->maxLength);
|
||||
case kDeleteSelection:
|
||||
return WillDeleteSelection(aSelection, info->collapsedAction, aCancel);
|
||||
case kUndo:
|
||||
return WillUndo(aSelection, aCancel);
|
||||
case kRedo:
|
||||
return WillRedo(aSelection, aCancel);
|
||||
case kSetTextProperty:
|
||||
return WillSetTextProperty(aSelection, aCancel);
|
||||
case kRemoveTextProperty:
|
||||
return WillRemoveTextProperty(aSelection, aCancel);
|
||||
case kOutputText:
|
||||
return WillOutputText(aSelection,
|
||||
info->outString,
|
||||
aCancel);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::DidDoAction(nsIDOMSelection *aSelection,
|
||||
nsRulesInfo *aInfo, nsresult aResult)
|
||||
{
|
||||
if (!aSelection || !aInfo)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// my kingdom for dynamic cast
|
||||
nsTextRulesInfo *info = NS_STATIC_CAST(nsTextRulesInfo*, aInfo);
|
||||
|
||||
switch (info->action)
|
||||
{
|
||||
case kInsertBreak:
|
||||
return DidInsertBreak(aSelection, aResult);
|
||||
case kInsertText:
|
||||
return DidInsertText(aSelection, aResult);
|
||||
case kDeleteSelection:
|
||||
return DidDeleteSelection(aSelection, info->collapsedAction, aResult);
|
||||
case kUndo:
|
||||
return DidUndo(aSelection, aResult);
|
||||
case kRedo:
|
||||
return DidRedo(aSelection, aResult);
|
||||
case kSetTextProperty:
|
||||
return DidSetTextProperty(aSelection, aResult);
|
||||
case kRemoveTextProperty:
|
||||
return DidRemoveTextProperty(aSelection, aResult);
|
||||
case kOutputText:
|
||||
return DidOutputText(aSelection, aResult);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
* Protected methods
|
||||
********************************************************/
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
if (!aSelection || !aCancel)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
|
||||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
|
||||
// check for the magic content node and delete it if it exists
|
||||
if (mBogusNode)
|
||||
{
|
||||
mEditor->DeleteNode(mBogusNode);
|
||||
mBogusNode = do_QueryInterface(nsnull);
|
||||
// there is no longer any legit selection, so clear it.
|
||||
aSelection->ClearSelection();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidInsert(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
if (!aSelection || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
if (mFlags & nsIHighLevelHTMLEditor::eEditorSingleLineMask) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
*aCancel = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidInsertBreak(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillInsertText(nsIDOMSelection *aSelection,
|
||||
PRBool *aCancel,
|
||||
PlaceholderTxn **aTxn,
|
||||
const nsString *aInString,
|
||||
nsString *aOutString,
|
||||
TypeInState aTypeInState,
|
||||
PRInt32 aMaxLength)
|
||||
{
|
||||
if (!aSelection || !aCancel || !aInString || !aOutString) {return NS_ERROR_NULL_POINTER;}
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
|
||||
nsresult result;
|
||||
|
||||
nsString inString = *aInString; // we might want to mutate the input
|
||||
// before setting the output, do that in a local var
|
||||
|
||||
if ((-1 != aMaxLength) && (mFlags & nsIHighLevelHTMLEditor::eEditorPlaintextMask))
|
||||
{
|
||||
// get the current text length
|
||||
// get the length of inString
|
||||
// if len(doc) is at or over max, cancel the insert
|
||||
// if l(doc) + l(input) > max, set aOutString to subset of inString so length = max
|
||||
PRInt32 docLength;
|
||||
result = mEditor->GetDocumentLength(&docLength);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (docLength >= aMaxLength)
|
||||
{
|
||||
*aOutString = "";
|
||||
*aCancel = PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRInt32 inCount = inString.Length();
|
||||
if ((inCount+docLength)>aMaxLength)
|
||||
{
|
||||
inString.Truncate(aMaxLength-docLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// initialize out params
|
||||
*aCancel = PR_FALSE;
|
||||
|
||||
if (mFlags & nsIHighLevelHTMLEditor::eEditorPasswordMask)
|
||||
{
|
||||
// manage the password buffer
|
||||
PRInt32 start, end;
|
||||
result = mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "getTextSelectionOffsets failed!");
|
||||
mPasswordText.Insert(inString, start);
|
||||
|
||||
char *password = mPasswordText.ToNewCString();
|
||||
printf("mPasswordText is %s\n", password);
|
||||
delete [] password;
|
||||
|
||||
// change the output to '*' only
|
||||
PRInt32 length = inString.Length();
|
||||
PRInt32 i;
|
||||
for (i=0; i<length; i++)
|
||||
*aOutString += '*';
|
||||
}
|
||||
else
|
||||
{
|
||||
*aOutString = inString;
|
||||
}
|
||||
|
||||
if (mBogusNode || (PR_TRUE==aTypeInState.IsAnySet()))
|
||||
{
|
||||
result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), (EditTxn **)aTxn);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!*aTxn) { return NS_ERROR_NULL_POINTER; }
|
||||
(*aTxn)->SetName(InsertTextTxn::gInsertTextTxnName);
|
||||
mEditor->Do(*aTxn);
|
||||
}
|
||||
result = WillInsert(aSelection, aCancel);
|
||||
if (NS_SUCCEEDED(result) && (PR_FALSE==*aCancel))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsAnySet())
|
||||
{ // for every property that is set, insert a new inline style node
|
||||
result = CreateStyleForInsertText(aSelection, aTypeInState);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidInsertText(nsIDOMSelection *aSelection,
|
||||
nsresult aResult)
|
||||
{
|
||||
return DidInsert(aSelection, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInState &aTypeInState)
|
||||
{
|
||||
// private method, we know aSelection is not null, and that it is collapsed
|
||||
NS_ASSERTION(nsnull!=aSelection, "bad selection");
|
||||
|
||||
// We know at least one style is set and we're about to insert at least one character.
|
||||
// If the selection is in a text node, split the node (even if we're at the beginning or end)
|
||||
// then put the text node inside new inline style parents.
|
||||
// Otherwise, create the text node and the new inline style parents.
|
||||
nsCOMPtr<nsIDOMNode>anchor;
|
||||
PRInt32 offset;
|
||||
nsresult result = aSelection->GetAnchorNode( getter_AddRefs(anchor));
|
||||
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(aSelection->GetAnchorOffset(&offset)) && anchor)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>anchorAsText;
|
||||
anchorAsText = do_QueryInterface(anchor);
|
||||
if (anchorAsText)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>newTextNode;
|
||||
// create an empty text node by splitting the selected text node according to offset
|
||||
if (0==offset)
|
||||
{
|
||||
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
||||
}
|
||||
else
|
||||
{
|
||||
PRUint32 length;
|
||||
anchorAsText->GetLength(&length);
|
||||
if (length==(PRUint32)offset)
|
||||
{
|
||||
// newTextNode will be the left node
|
||||
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
||||
// but we want the right node in this case
|
||||
newTextNode = do_QueryInterface(anchor);
|
||||
}
|
||||
else
|
||||
{
|
||||
// splitting anchor twice sets newTextNode as an empty text node between
|
||||
// two halves of the original text node
|
||||
result = mEditor->SplitNode(anchorAsText, offset, getter_AddRefs(newTextNode));
|
||||
result = mEditor->SplitNode(anchorAsText, 0, getter_AddRefs(newTextNode));
|
||||
}
|
||||
}
|
||||
// now we have the new text node we are going to insert into.
|
||||
// create style nodes or move it up the content hierarchy as needed.
|
||||
if ((NS_SUCCEEDED(result)) && newTextNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_BOLD))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetBold()) {
|
||||
result = InsertStyleNode(newTextNode, nsIEditProperty::b, aSelection, getter_AddRefs(newStyleNode));
|
||||
}
|
||||
else {
|
||||
printf("not yet implemented, make not bold in a bold context\n");
|
||||
}
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_ITALIC))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetItalic()) {
|
||||
result = InsertStyleNode(newTextNode, nsIEditProperty::i, aSelection, getter_AddRefs(newStyleNode));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("not yet implemented, make not italic in a italic context\n");
|
||||
}
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_UNDERLINE))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetUnderline()) {
|
||||
result = InsertStyleNode(newTextNode, nsIEditProperty::u, aSelection, getter_AddRefs(newStyleNode));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("not yet implemented, make not underline in an underline context\n");
|
||||
}
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTCOLOR))
|
||||
{
|
||||
nsAutoString value;
|
||||
aTypeInState.GetFontColor(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::color->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTFACE))
|
||||
{
|
||||
nsAutoString value;
|
||||
aTypeInState.GetFontFace(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::face->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTSIZE))
|
||||
{
|
||||
nsAutoString value;
|
||||
aTypeInState.GetFontSize(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::size->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("not yet implemented. selection is not text.\n");
|
||||
}
|
||||
}
|
||||
else // we have no selection, so insert a style tag in the body
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
mEditor->GetDocument(getter_AddRefs(doc));
|
||||
nsCOMPtr<nsIDOMNodeList>nodeList;
|
||||
nsAutoString bodyTag = "body";
|
||||
result = doc->GetElementsByTagName(bodyTag, getter_AddRefs(nodeList));
|
||||
if ((NS_SUCCEEDED(result)) && nodeList)
|
||||
{
|
||||
PRUint32 count;
|
||||
nodeList->GetLength(&count);
|
||||
NS_ASSERTION(1==count, "there is not exactly 1 body in the document!");
|
||||
nsCOMPtr<nsIDOMNode>bodyNode;
|
||||
result = nodeList->Item(0, getter_AddRefs(bodyNode));
|
||||
if ((NS_SUCCEEDED(result)) && bodyNode)
|
||||
{ // now we've got the body tag. insert the style tag
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_BOLD))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetBold()) {
|
||||
InsertStyleAndNewTextNode(bodyNode, nsIEditProperty::b, aSelection);
|
||||
}
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_ITALIC))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetItalic()) {
|
||||
InsertStyleAndNewTextNode(bodyNode, nsIEditProperty::i, aSelection);
|
||||
}
|
||||
}
|
||||
if (aTypeInState.IsSet(NS_TYPEINSTATE_UNDERLINE))
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.GetUnderline()) {
|
||||
InsertStyleAndNewTextNode(bodyNode, nsIEditProperty::u, aSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::CreateFontStyleForInsertText(nsIDOMNode *aNewTextNode,
|
||||
const nsString &aAttr,
|
||||
const nsString &aValue,
|
||||
nsIDOMSelection *aSelection)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
||||
if (0!=aValue.Length())
|
||||
{
|
||||
result = InsertStyleNode(aNewTextNode, nsIEditProperty::font, aSelection, getter_AddRefs(newStyleNode));
|
||||
if (NS_SUCCEEDED(result) && newStyleNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement>element = do_QueryInterface(newStyleNode);
|
||||
if (element) {
|
||||
result = mEditor->SetAttribute(element, aAttr, aValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("not yet implemented, undo font in an font context\n");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::InsertStyleNode(nsIDOMNode *aNode,
|
||||
nsIAtom *aTag,
|
||||
nsIDOMSelection *aSelection,
|
||||
nsIDOMNode **aNewNode)
|
||||
{
|
||||
NS_ASSERTION(aNode && aTag, "bad args");
|
||||
if (!aNode || !aTag) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode>parent;
|
||||
aNode->GetParentNode(getter_AddRefs(parent));
|
||||
PRInt32 offsetInParent;
|
||||
nsEditor::GetChildOffset(aNode, parent, offsetInParent);
|
||||
nsAutoString tag;
|
||||
aTag->ToString(tag);
|
||||
result = mEditor->CreateNode(tag, parent, offsetInParent, aNewNode);
|
||||
if ((NS_SUCCEEDED(result)) && *aNewNode)
|
||||
{
|
||||
result = mEditor->DeleteNode(aNode);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = mEditor->InsertNode(aNode, *aNewNode, 0);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
if (aSelection) {
|
||||
aSelection->Collapse(aNode, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::InsertStyleAndNewTextNode(nsIDOMNode *aParentNode, nsIAtom *aTag, nsIDOMSelection *aSelection)
|
||||
{
|
||||
NS_ASSERTION(aParentNode && aTag, "bad args");
|
||||
if (!aParentNode || !aTag) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
nsresult result;
|
||||
// if the selection already points to a text node, just call InsertStyleNode()
|
||||
if (aSelection)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>anchor;
|
||||
PRInt32 offset;
|
||||
result = aSelection->GetAnchorNode(getter_AddRefs(anchor));
|
||||
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(aSelection->GetAnchorOffset(&offset)) && anchor)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>anchorAsText;
|
||||
anchorAsText = do_QueryInterface(anchor);
|
||||
if (anchorAsText)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> newStyleNode;
|
||||
result = InsertStyleNode(anchor, aTag, aSelection, getter_AddRefs(newStyleNode));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we get here, there is no selected text node so we create one.
|
||||
nsAutoString tag;
|
||||
aTag->ToString(tag);
|
||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
||||
nsCOMPtr<nsIDOMNode>newTextNode;
|
||||
result = mEditor->CreateNode(tag, aParentNode, 0, getter_AddRefs(newStyleNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = mEditor->CreateNode(nsEditor::GetTextNodeTag(), newStyleNode, 0, getter_AddRefs(newTextNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (aSelection) {
|
||||
aSelection->Collapse(newTextNode, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillSetTextProperty(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// XXX: should probably return a success value other than NS_OK that means "not allowed"
|
||||
if (nsIHighLevelHTMLEditor::eEditorPlaintextMask & mFlags) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidSetTextProperty(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillRemoveTextProperty(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// XXX: should probably return a success value other than NS_OK that means "not allowed"
|
||||
if (nsIHighLevelHTMLEditor::eEditorPlaintextMask & mFlags) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidRemoveTextProperty(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillDeleteSelection(nsIDOMSelection *aSelection,
|
||||
nsIEditor::ESelectionCollapseDirection aCollapsedAction,
|
||||
PRBool *aCancel)
|
||||
{
|
||||
if (!aSelection || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
|
||||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
|
||||
// if there is only bogus content, cancel the operation
|
||||
if (mBogusNode) {
|
||||
*aCancel = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
if (mFlags & nsIHighLevelHTMLEditor::eEditorPasswordMask)
|
||||
{
|
||||
// manage the password buffer
|
||||
PRInt32 start, end;
|
||||
mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||
if (end==start)
|
||||
{ // collapsed selection
|
||||
if (nsIEditor::eDeletePrevious==aCollapsedAction && 0<start) { // del back
|
||||
mPasswordText.Cut(start-1, 1);
|
||||
}
|
||||
else if (nsIEditor::eDeleteNext==aCollapsedAction) { // del forward
|
||||
mPasswordText.Cut(start, 1);
|
||||
}
|
||||
// otherwise nothing to do for this collapsed selection
|
||||
}
|
||||
else { // extended selection
|
||||
mPasswordText.Cut(start, end-start);
|
||||
}
|
||||
|
||||
char *password = mPasswordText.ToNewCString();
|
||||
printf("mPasswordText is %s\n", password);
|
||||
delete [] password;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// if the document is empty, insert a bogus text node with a
|
||||
// if we ended up with consecutive text nodes, merge them
|
||||
nsresult
|
||||
nsTextEditRules::DidDeleteSelection(nsIDOMSelection *aSelection,
|
||||
nsIEditor::ESelectionCollapseDirection aCollapsedAction,
|
||||
nsresult aResult)
|
||||
{
|
||||
nsresult result = aResult; // if aResult is an error, we just return it
|
||||
if (!aSelection) { return NS_ERROR_NULL_POINTER; }
|
||||
PRBool isCollapsed;
|
||||
aSelection->GetIsCollapsed(&isCollapsed);
|
||||
NS_ASSERTION(PR_TRUE==isCollapsed, "selection not collapsed after delete selection.");
|
||||
// if the delete selection resulted in no content
|
||||
// insert a special bogus text node with a character in it.
|
||||
if (NS_SUCCEEDED(result)) // only do this work if DeleteSelection completed successfully
|
||||
{
|
||||
result = CreateBogusNodeIfNeeded(aSelection);
|
||||
// if we don't have an empty document, check the selection to see if any collapsing is necessary
|
||||
if (!mBogusNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>anchor;
|
||||
PRInt32 offset;
|
||||
result = aSelection->GetAnchorNode(getter_AddRefs(anchor));
|
||||
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(aSelection->GetAnchorOffset(&offset)) && anchor)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> anchorChildren;
|
||||
result = anchor->GetChildNodes(getter_AddRefs(anchorChildren));
|
||||
nsCOMPtr<nsIDOMNode> selectedNode;
|
||||
if ((NS_SUCCEEDED(result)) && anchorChildren) {
|
||||
result = anchorChildren->Item(offset, getter_AddRefs(selectedNode));
|
||||
}
|
||||
else {
|
||||
selectedNode = do_QueryInterface(anchor);
|
||||
}
|
||||
if ((NS_SUCCEEDED(result)) && selectedNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>selectedNodeAsText;
|
||||
selectedNodeAsText = do_QueryInterface(selectedNode);
|
||||
if (selectedNodeAsText)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> siblingNode;
|
||||
selectedNode->GetPreviousSibling(getter_AddRefs(siblingNode));
|
||||
if (siblingNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>siblingNodeAsText;
|
||||
siblingNodeAsText = do_QueryInterface(siblingNode);
|
||||
if (siblingNodeAsText)
|
||||
{
|
||||
PRUint32 siblingLength; // the length of siblingNode before the join
|
||||
siblingNodeAsText->GetLength(&siblingLength);
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
selectedNode->GetParentNode(getter_AddRefs(parentNode));
|
||||
result = mEditor->JoinNodes(siblingNode, selectedNode, parentNode);
|
||||
// selectedNode will remain after the join, siblingNode is removed
|
||||
}
|
||||
}
|
||||
selectedNode->GetNextSibling(getter_AddRefs(siblingNode));
|
||||
if (siblingNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>siblingNodeAsText;
|
||||
siblingNodeAsText = do_QueryInterface(siblingNode);
|
||||
if (siblingNodeAsText)
|
||||
{
|
||||
PRUint32 selectedNodeLength; // the length of siblingNode before the join
|
||||
selectedNodeAsText->GetLength(&selectedNodeLength);
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
selectedNode->GetParentNode(getter_AddRefs(parentNode));
|
||||
result = mEditor->JoinNodes(selectedNode, siblingNode, parentNode);
|
||||
// selectedNode will remain after the join, siblingNode is removed
|
||||
// set selection
|
||||
aSelection->Collapse(siblingNode, selectedNodeLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillUndo(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
if (!aSelection || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* the idea here is to see if the magic empty node has suddenly reappeared as the result of the undo.
|
||||
* if it has, set our state so we remember it.
|
||||
* There is a tradeoff between doing here and at redo, or doing it everywhere else that might care.
|
||||
* Since undo and redo are relatively rare, it makes sense to take the (small) performance hit here.
|
||||
*/
|
||||
nsresult
|
||||
nsTextEditRules:: DidUndo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsresult result = aResult; // if aResult is an error, we return it.
|
||||
if (!aSelection) { return NS_ERROR_NULL_POINTER; }
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (mBogusNode) {
|
||||
mBogusNode = do_QueryInterface(nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>node;
|
||||
PRInt32 offset;
|
||||
result = aSelection->GetAnchorNode(getter_AddRefs(node));
|
||||
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(aSelection->GetAnchorOffset(&offset)) && node)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement>element;
|
||||
element = do_QueryInterface(node);
|
||||
if (element)
|
||||
{
|
||||
nsAutoString att(nsEditor::kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(nsEditor::kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp;
|
||||
result = node->GetParentNode(getter_AddRefs(temp));
|
||||
node = do_QueryInterface(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillRedo(nsIDOMSelection *aSelection, PRBool *aCancel)
|
||||
{
|
||||
if (!aSelection || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidRedo(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
nsresult result = aResult; // if aResult is an error, we return it.
|
||||
if (!aSelection) { return NS_ERROR_NULL_POINTER; }
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
if (mBogusNode) {
|
||||
mBogusNode = do_QueryInterface(nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>node;
|
||||
PRInt32 offset;
|
||||
result = aSelection->GetAnchorNode(getter_AddRefs(node));
|
||||
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(aSelection->GetAnchorOffset(&offset)) && node)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement>element;
|
||||
element = do_QueryInterface(node);
|
||||
if (element)
|
||||
{
|
||||
nsAutoString att(nsEditor::kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val;
|
||||
(void)element->GetAttribute(att, val);
|
||||
if (val.Equals(nsEditor::kMOZEditorBogusNodeValue)) {
|
||||
mBogusNode = do_QueryInterface(element);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp;
|
||||
result = node->GetParentNode(getter_AddRefs(temp));
|
||||
node = do_QueryInterface(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::WillOutputText(nsIDOMSelection *aSelection,
|
||||
nsString *aOutString,
|
||||
PRBool *aCancel)
|
||||
{
|
||||
// null selection ok
|
||||
if (!aOutString || !aCancel) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
|
||||
if (mFlags & nsIHighLevelHTMLEditor::eEditorPasswordMask)
|
||||
{
|
||||
*aOutString = mPasswordText;
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::DidOutputText(nsIDOMSelection *aSelection, nsresult aResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
||||
{
|
||||
if (!aSelection) { return NS_ERROR_NULL_POINTER; }
|
||||
if (!mEditor) { return NS_ERROR_NULL_POINTER; }
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
mEditor->GetDocument(getter_AddRefs(doc));
|
||||
nsCOMPtr<nsIDOMNodeList>nodeList;
|
||||
nsAutoString bodyTag = "body";
|
||||
nsresult result = doc->GetElementsByTagName(bodyTag, getter_AddRefs(nodeList));
|
||||
if ((NS_SUCCEEDED(result)) && nodeList)
|
||||
{
|
||||
PRUint32 count;
|
||||
nodeList->GetLength(&count);
|
||||
NS_ASSERTION(1==count, "there is not exactly 1 body in the document!");
|
||||
nsCOMPtr<nsIDOMNode>bodyNode;
|
||||
result = nodeList->Item(0, getter_AddRefs(bodyNode));
|
||||
if ((NS_SUCCEEDED(result)) && bodyNode)
|
||||
{ // now we've got the body tag.
|
||||
// iterate the body tag, looking for editable content
|
||||
// if no editable content is found, insert the bogus node
|
||||
PRBool needsBogusContent=PR_TRUE;
|
||||
nsCOMPtr<nsIDOMNode>bodyChild;
|
||||
result = bodyNode->GetFirstChild(getter_AddRefs(bodyChild));
|
||||
while ((NS_SUCCEEDED(result)) && bodyChild)
|
||||
{
|
||||
if (PR_TRUE==mEditor->IsEditable(bodyChild))
|
||||
{
|
||||
needsBogusContent = PR_FALSE;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode>temp;
|
||||
bodyChild->GetNextSibling(getter_AddRefs(temp));
|
||||
bodyChild = do_QueryInterface(temp);
|
||||
}
|
||||
if (PR_TRUE==needsBogusContent)
|
||||
{
|
||||
// set mBogusNode to be the newly created <P>
|
||||
result = mEditor->CreateNode(nsAutoString("P"), bodyNode, 0,
|
||||
getter_AddRefs(mBogusNode));
|
||||
if ((NS_SUCCEEDED(result)) && mBogusNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>newTNode;
|
||||
result = mEditor->CreateNode(nsEditor::GetTextNodeTag(), mBogusNode, 0,
|
||||
getter_AddRefs(newTNode));
|
||||
if ((NS_SUCCEEDED(result)) && newTNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCharacterData>newNodeAsText;
|
||||
newNodeAsText = do_QueryInterface(newTNode);
|
||||
if (newNodeAsText)
|
||||
{
|
||||
nsAutoString data;
|
||||
data += 160;
|
||||
newNodeAsText->SetData(data);
|
||||
aSelection->Collapse(newTNode, 0);
|
||||
}
|
||||
}
|
||||
// make sure we know the PNode is bogus
|
||||
nsCOMPtr<nsIDOMElement>newPElement;
|
||||
newPElement = do_QueryInterface(mBogusNode);
|
||||
if (newPElement)
|
||||
{
|
||||
nsAutoString att(nsEditor::kMOZEditorBogusNodeAttr);
|
||||
nsAutoString val(nsEditor::kMOZEditorBogusNodeValue);
|
||||
newPElement->SetAttribute(att, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
201
mozilla/editor/base/nsTextEditRules.h
Normal file
201
mozilla/editor/base/nsTextEditRules.h
Normal file
@@ -0,0 +1,201 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsTextEditRules_h__
|
||||
#define nsTextEditRules_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsHTMLEditor.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
#include "nsEditRules.h"
|
||||
#include "TypeInState.h"
|
||||
|
||||
class PlaceholderTxn;
|
||||
class nsTextEditor;
|
||||
|
||||
/** Object that encapsulates HTML text-specific editing rules.
|
||||
*
|
||||
* To be a good citizen, edit rules must live by these restrictions:
|
||||
* 1. All data manipulation is through the editor.
|
||||
* Content nodes in the document tree must <B>not</B> be manipulated directly.
|
||||
* Content nodes in document fragments that are not part of the document itself
|
||||
* may be manipulated at will. Operations on document fragments must <B>not</B>
|
||||
* go through the editor.
|
||||
* 2. Selection must not be explicitly set by the rule method.
|
||||
* Any manipulation of Selection must be done by the editor.
|
||||
*/
|
||||
class nsTextEditRules : public nsEditRules
|
||||
{
|
||||
public:
|
||||
|
||||
nsTextEditRules(PRUint32 aFlags);
|
||||
virtual ~nsTextEditRules();
|
||||
|
||||
// nsEditRules methods
|
||||
NS_IMETHOD Init(nsHTMLEditor *aEditor);
|
||||
NS_IMETHOD WillDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel);
|
||||
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
|
||||
// nsTextEditRules action id's
|
||||
enum
|
||||
{
|
||||
// any editor that has a txn mgr
|
||||
kUndo = 1000,
|
||||
kRedo = 1001,
|
||||
// text actions
|
||||
kInsertText = 2000,
|
||||
kDeleteSelection = 2001,
|
||||
kSetTextProperty = 2003,
|
||||
kRemoveTextProperty = 2004,
|
||||
kOutputText = 2005,
|
||||
// html only action
|
||||
kInsertBreak = 3000,
|
||||
kMakeList = 3001,
|
||||
kIndent = 3002,
|
||||
kOutdent = 3003,
|
||||
kAlign = 3004,
|
||||
kMakeHeader = 3005,
|
||||
kMakeAddress = 3006,
|
||||
kMakePRE = 3007
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
// nsTextEditRules implementation methods
|
||||
nsresult WillInsertText(nsIDOMSelection *aSelection,
|
||||
PRBool *aCancel,
|
||||
PlaceholderTxn **aTxn,
|
||||
const nsString *inString,
|
||||
nsString *outString,
|
||||
TypeInState typeInState,
|
||||
PRInt32 aMaxLength);
|
||||
nsresult DidInsertText(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
nsresult CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInState &aTypeInState);
|
||||
|
||||
nsresult WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidInsertBreak(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidInsert(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillDeleteSelection(nsIDOMSelection *aSelection,
|
||||
nsIEditor::ESelectionCollapseDirection aCollapsedAction,
|
||||
PRBool *aCancel);
|
||||
nsresult DidDeleteSelection(nsIDOMSelection *aSelection,
|
||||
nsIEditor::ESelectionCollapseDirection aCollapsedAction,
|
||||
nsresult aResult);
|
||||
|
||||
nsresult WillSetTextProperty(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidSetTextProperty(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillRemoveTextProperty(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidRemoveTextProperty(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillUndo(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidUndo(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillRedo(nsIDOMSelection *aSelection, PRBool *aCancel);
|
||||
nsresult DidRedo(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
nsresult WillOutputText(nsIDOMSelection *aSelection, nsString *aOutText, PRBool *aCancel);
|
||||
nsresult DidOutputText(nsIDOMSelection *aSelection, nsresult aResult);
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
/** insert aNode into a new style node of type aTag.
|
||||
* aSelection is optional. If provided, aSelection is set to (aNode, 0)
|
||||
* if aNode was successfully placed in a new style node
|
||||
* @param aNewStyleNode [OUT] The newly created style node, if result is successful
|
||||
* undefined if result is a failure.
|
||||
*/
|
||||
nsresult InsertStyleNode(nsIDOMNode *aNode,
|
||||
nsIAtom *aTag,
|
||||
nsIDOMSelection *aSelection,
|
||||
nsIDOMNode **aNewStyleNode);
|
||||
|
||||
/** inserts a new <FONT> node and sets the aAttr attribute to aValue */
|
||||
nsresult CreateFontStyleForInsertText(nsIDOMNode *aNewTextNode,
|
||||
const nsString &aAttr,
|
||||
const nsString &aValue,
|
||||
nsIDOMSelection *aSelection);
|
||||
|
||||
/** create a new style node of type aTag in aParentNode, and put a new text node
|
||||
* in the new style node.
|
||||
* If aSelection is provided and points to a text node, just call InsertStyleNode instead.
|
||||
* aSelection is optional. If provided, aSelection is set to (newTextNode, 0)
|
||||
* if newTextNode was successfully created.
|
||||
*/
|
||||
nsresult InsertStyleAndNewTextNode(nsIDOMNode *aParentNode,
|
||||
nsIAtom *aTag,
|
||||
nsIDOMSelection *aSelection);
|
||||
|
||||
/** creates a bogus text node if the document has no editable content */
|
||||
nsresult CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection);
|
||||
|
||||
/** enforce selection must be inside PRE node */
|
||||
nsresult PinSelectionInPRE(nsIDOMSelection *aSelection);
|
||||
|
||||
// data
|
||||
nsHTMLEditor *mEditor; // note that we do not refcount the editor
|
||||
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
||||
nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc
|
||||
PRUint32 mFlags;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class nsTextRulesInfo : public nsRulesInfo
|
||||
{
|
||||
public:
|
||||
|
||||
nsTextRulesInfo(int aAction) :
|
||||
nsRulesInfo(aAction),
|
||||
placeTxn(0),
|
||||
inString(0),
|
||||
outString(0),
|
||||
typeInState(),
|
||||
maxLength(-1),
|
||||
collapsedAction(nsIEditor::eDeleteNext)
|
||||
{};
|
||||
|
||||
virtual ~nsTextRulesInfo() {};
|
||||
|
||||
// kInsertText
|
||||
PlaceholderTxn **placeTxn;
|
||||
const nsString *inString;
|
||||
nsString *outString;
|
||||
TypeInState typeInState;
|
||||
PRInt32 maxLength;
|
||||
|
||||
// kDeleteSelection
|
||||
nsIEditor::ESelectionCollapseDirection collapsedAction;
|
||||
|
||||
// kMakeList
|
||||
PRBool bOrdered;
|
||||
|
||||
// kAlign
|
||||
const nsString *alignType;
|
||||
};
|
||||
|
||||
#endif //nsTextEditRules_h__
|
||||
|
||||
661
mozilla/editor/base/nsTextEditor.cpp
Normal file
661
mozilla/editor/base/nsTextEditor.cpp
Normal file
@@ -0,0 +1,661 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL") you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#error "This file is no longer used"
|
||||
|
||||
#include "nsTextEditor.h"
|
||||
#include "nsEditorEventListeners.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMTextListener.h"
|
||||
#include "nsIDiskDocument.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsEditorCID.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#if DEBUG
|
||||
#include "TextEditorTest.h"
|
||||
#endif
|
||||
|
||||
// transactions the text editor knows how to build itself
|
||||
#include "TransactionFactory.h"
|
||||
#include "PlaceholderTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIToolkit.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIFileWidget.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
#include "nsIClipboard.h"
|
||||
#include "nsITransferable.h"
|
||||
//#include "nsIFormatConverter.h"
|
||||
|
||||
// Drag & Drop, Clipboard Support
|
||||
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
||||
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
||||
//static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsTextEditRules.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsAOLCiter.h"
|
||||
#include "nsInternetCiter.h"
|
||||
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
#include "nsJSEditorLog.h"
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
|
||||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gNoisy = PR_FALSE;
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* nsTextEditor implementation
|
||||
****************************************************************************/
|
||||
|
||||
nsTextEditor::nsTextEditor()
|
||||
: mTypeInState(nsnull)
|
||||
, mRules(nsnull)
|
||||
, mKeyListenerP(nsnull)
|
||||
, mIsComposing(PR_FALSE)
|
||||
{
|
||||
// Done in nsEditor
|
||||
// NS_INIT_REFCNT();
|
||||
mRules = nsnull;
|
||||
mMaxTextLength = -1;
|
||||
mWrapColumn = 72;
|
||||
}
|
||||
|
||||
nsTextEditor::~nsTextEditor()
|
||||
{}
|
||||
|
||||
// Adds appropriate AddRef, Release, and QueryInterface methods for derived class
|
||||
//NS_IMPL_ISUPPORTS_INHERITED(nsTextEditor, nsEditor, nsITextEditor)
|
||||
|
||||
//NS_IMPL_ADDREF_INHERITED(Class, Super)
|
||||
NS_IMETHODIMP_(nsrefcnt) nsTextEditor::AddRef(void)
|
||||
{
|
||||
return nsEditor::AddRef();
|
||||
}
|
||||
|
||||
//NS_IMPL_RELEASE_INHERITED(Class, Super)
|
||||
NS_IMETHODIMP_(nsrefcnt) nsTextEditor::Release(void)
|
||||
{
|
||||
return nsEditor::Release();
|
||||
}
|
||||
|
||||
//NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface)
|
||||
NS_IMETHODIMP nsTextEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(nsITextEditor::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsITextEditor*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return nsEditor::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc,
|
||||
nsIPresShell *aPresShell)
|
||||
{}
|
||||
|
||||
void nsTextEditor::HandleEventListenerError()
|
||||
{}
|
||||
|
||||
void nsTextEditor::InitRules()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::GetFlags(PRUint32 *aFlags)
|
||||
{
|
||||
if (!mRules || !aFlags) { return NS_ERROR_NULL_POINTER; }
|
||||
return mRules->GetFlags(aFlags);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::SetFlags(PRUint32 aFlags)
|
||||
{
|
||||
if (!mRules) { return NS_ERROR_NULL_POINTER; }
|
||||
return mRules->SetFlags(aFlags);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::GetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAny, PRBool &aAll)
|
||||
{}
|
||||
|
||||
void nsTextEditor::IsTextStyleSet(nsIStyleContext *aSC,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
PRBool &aIsSet) const
|
||||
{}
|
||||
|
||||
// this will NOT find aAttribute unless aAttribute has a non-null value
|
||||
// so singleton attributes like <Table border> will not be matched!
|
||||
void nsTextEditor::IsTextPropertySetByContent(nsIDOMNode *aNode,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aIsSet,
|
||||
nsIDOMNode **aStyleNode) const
|
||||
{}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::RemoveTextProperty(nsIAtom *aProperty, const nsString *aAttribute)
|
||||
{}
|
||||
|
||||
void nsTextEditor::GetTextSelectionOffsetsForRange(nsIDOMSelection *aSelection,
|
||||
nsIDOMNode **aParent,
|
||||
PRInt32 &aStartOffset,
|
||||
PRInt32 &aEndOffset)
|
||||
{}
|
||||
|
||||
void nsTextEditor::ResetTextSelectionForRange(nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMSelection *aSelection)
|
||||
{}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::DeleteSelection(nsIEditor::ESelectionCollapseDirection aAction)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::InsertText(const nsString& aStringToInsert)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SetMaxTextLength(PRInt32 aMaxTextLength)
|
||||
{
|
||||
mMaxTextLength = aMaxTextLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::GetMaxTextLength(PRInt32& aMaxTextLength)
|
||||
{
|
||||
aMaxTextLength = mMaxTextLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::InsertBreak()
|
||||
{
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
nsAutoJSEditorLogLock logLock(mJSEditorLog);
|
||||
|
||||
if (mJSEditorLog)
|
||||
mJSEditorLog->InsertBreak();
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
PRBool cancel= PR_FALSE;
|
||||
|
||||
// pre-process
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertBreak);
|
||||
nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel);
|
||||
if ((PR_FALSE==cancel) && (NS_SUCCEEDED(result)))
|
||||
{
|
||||
// For plainttext just pass newlines through
|
||||
nsAutoString key;
|
||||
key += '\n';
|
||||
result = InsertText(key);
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
result = mRules->DidDoAction(selection, &ruleInfo, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::EnableUndo(PRBool aEnable)
|
||||
{
|
||||
return nsEditor::EnableUndo(aEnable);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Undo(PRUint32 aCount)
|
||||
{
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
nsAutoJSEditorLogLock logLock(mJSEditorLog);
|
||||
|
||||
if (mJSEditorLog)
|
||||
mJSEditorLog->Undo(aCount);
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
PRBool cancel= PR_FALSE;
|
||||
|
||||
// pre-process
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
nsTextRulesInfo ruleInfo(nsTextEditRules::kUndo);
|
||||
nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel);
|
||||
if ((PR_FALSE==cancel) && (NS_SUCCEEDED(result)))
|
||||
{
|
||||
result = nsEditor::Undo(aCount);
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
result = mRules->DidDoAction(selection, &ruleInfo, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
||||
{
|
||||
return nsEditor::CanUndo(aIsEnabled, aCanUndo);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Redo(PRUint32 aCount)
|
||||
{
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
nsAutoJSEditorLogLock logLock(mJSEditorLog);
|
||||
|
||||
if (mJSEditorLog)
|
||||
mJSEditorLog->Redo(aCount);
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
PRBool cancel= PR_FALSE;
|
||||
|
||||
// pre-process
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo);
|
||||
nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel);
|
||||
if ((PR_FALSE==cancel) && (NS_SUCCEEDED(result)))
|
||||
{
|
||||
result = nsEditor::Redo(aCount);
|
||||
nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
result = mRules->DidDoAction(selection, &ruleInfo, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
||||
{
|
||||
return nsEditor::CanRedo(aIsEnabled, aCanRedo);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::BeginTransaction()
|
||||
{
|
||||
return nsEditor::BeginTransaction();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::EndTransaction()
|
||||
{
|
||||
return nsEditor::EndTransaction();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SelectAll()
|
||||
{
|
||||
return nsEditor::SelectAll();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::BeginningOfDocument()
|
||||
{
|
||||
return nsEditor::BeginningOfDocument();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::EndOfDocument()
|
||||
{
|
||||
return nsEditor::EndOfDocument();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::ScrollUp(nsIAtom *aIncrement)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::ScrollDown(nsIAtom *aIncrement)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::ScrollIntoView(PRBool aScrollToBegin)
|
||||
{
|
||||
return nsEditor::ScrollIntoView(aScrollToBegin);
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
||||
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SaveDocument(PRBool saveAs, PRBool saveCopy)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Save()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SaveAs(PRBool aSavingCopy)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Cut()
|
||||
{
|
||||
return nsEditor::Cut();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Copy()
|
||||
{
|
||||
return nsEditor::Copy();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::Paste()
|
||||
{}
|
||||
|
||||
//
|
||||
// Similar to that in nsEditor::Paste except that it does indentation:
|
||||
//
|
||||
NS_IMETHODIMP nsTextEditor::PasteAsQuotation()
|
||||
{
|
||||
#ifdef ENABLE_JS_EDITOR_LOG
|
||||
nsAutoJSEditorLogLock logLock(mJSEditorLog);
|
||||
|
||||
if (mJSEditorLog)
|
||||
mJSEditorLog->PasteAsQuotation();
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
nsString stuffToPaste;
|
||||
|
||||
// Get Clipboard Service
|
||||
nsIClipboard* clipboard;
|
||||
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
|
||||
nsIClipboard::GetIID(),
|
||||
(nsISupports **)&clipboard);
|
||||
|
||||
// Create generic Transferable for getting the data
|
||||
nsCOMPtr<nsITransferable> trans;
|
||||
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
||||
nsITransferable::GetIID(),
|
||||
(void**) getter_AddRefs(trans));
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// Get nsITransferable interface for getting the data from the clipboard
|
||||
if (trans)
|
||||
{
|
||||
// We only handle plaintext pastes here
|
||||
nsAutoString flavor(kTextMime);
|
||||
|
||||
trans->AddDataFlavor(&flavor);
|
||||
|
||||
// Get the Data from the clipboard
|
||||
clipboard->GetData(trans);
|
||||
|
||||
// Now we ask the transferable for the data
|
||||
// it still owns the data, we just have a pointer to it.
|
||||
// If it can't support a "text" output of the data the call will fail
|
||||
char *str = 0;
|
||||
PRUint32 len;
|
||||
if (NS_OK == trans->GetTransferData(&flavor, (void **)&str, &len)) {
|
||||
|
||||
// Make adjustments for null terminated strings
|
||||
if (str && len > 0) {
|
||||
// stuffToPaste is ready for insertion into the content
|
||||
stuffToPaste.SetString(str, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nsServiceManager::ReleaseService(kCClipboardCID, clipboard);
|
||||
|
||||
return InsertAsQuotation(stuffToPaste);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::InsertAsQuotation(const nsString& aQuotedText)
|
||||
{}
|
||||
|
||||
//
|
||||
// Get the wrap width for the first PRE tag in the document.
|
||||
// If no PRE tag, throw an error.
|
||||
//
|
||||
NS_IMETHODIMP nsTextEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
|
||||
{}
|
||||
|
||||
//
|
||||
// Change the wrap width on the first <PRE> tag in this document.
|
||||
// (Eventually want to search for more than one in case there are
|
||||
// interspersed quoted text blocks.)
|
||||
//
|
||||
NS_IMETHODIMP nsTextEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::ApplyStyleSheet(const nsString& aURL)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharset,
|
||||
PRUint32 aFlags)
|
||||
{}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::MoveContentOfNodeIntoNewParent(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aNewParentNode,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset)
|
||||
{}
|
||||
|
||||
/* this should only get called if the only intervening nodes are inline style nodes */
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue)
|
||||
{}
|
||||
|
||||
//XXX won't work for selections that are not leaf nodes!
|
||||
// should fix up the end points to make sure they are leaf nodes
|
||||
NS_IMETHODIMP nsTextEditor::MoveContiguousContentIntoNewParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aGrandParentNode,
|
||||
nsIDOMNode *aNewParentNode)
|
||||
{}
|
||||
|
||||
|
||||
/* this wraps every selected text node in a new inline style node if needed
|
||||
the text nodes are treated as being unique -- each needs it's own style node
|
||||
if the style is not already present.
|
||||
each action has immediate effect on the content tree and resolved style, so
|
||||
doing outermost text nodes first removes the need for interior style nodes in some cases.
|
||||
XXX: need to code test to see if new style node is needed
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::SetTextPropertiesForNodeWithDifferentParents(nsIDOMRange *aRange,
|
||||
nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::RemoveTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute)
|
||||
{}
|
||||
|
||||
/* this should only get called if the only intervening nodes are inline style nodes */
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::RemoveTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::RemoveTextPropertiesForNodeWithDifferentParents(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute)
|
||||
{}
|
||||
|
||||
TypeInState * nsTextEditor::GetTypeInState()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::SetTypeInStateForProperty(TypeInState &aTypeInState,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::SetBackgroundColor(const nsString& aColor)
|
||||
{}
|
||||
|
||||
// This file should be rearranged to put all methods that simply call nsEditor together
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
return nsEditor::CopyAttributes(aDestNode, aSourceNode);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::BeginComposition(void)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::SetCompositionString(const nsString& aCompositionString,nsIDOMTextRangeList* aTextRangeList)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::EndComposition(void)
|
||||
{}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (!outNumTests || !outNumTestsFailed)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
TextEditorTest *tester = new TextEditorTest();
|
||||
if (!tester)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
tester->Run(this, outNumTests, outNumTestsFailed);
|
||||
delete tester;
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditor::GetDocumentLength(PRInt32 *aCount)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
336
mozilla/editor/base/nsTextEditor.h
Normal file
336
mozilla/editor/base/nsTextEditor.h
Normal file
@@ -0,0 +1,336 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#error "This file is no longer used"
|
||||
|
||||
#ifndef nsTextEditor_h__
|
||||
#define nsTextEditor_h__
|
||||
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsTextEditRules.h"
|
||||
#include "TypeInState.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIStyleContext;
|
||||
class nsIDOMRange;
|
||||
class nsIDOMNode;
|
||||
|
||||
/**
|
||||
* The text editor implementation.<br>
|
||||
* Use to edit text represented as a DOM tree.
|
||||
* This class is used for editing both plain text and rich text (attributed text).
|
||||
*/
|
||||
class nsTextEditor : public nsEditor, public nsITextEditor
|
||||
{
|
||||
public:
|
||||
// see nsITextEditor for documentation
|
||||
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE macro used is for classes that inherit from
|
||||
// another class. Only the base class should use NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsTextEditor();
|
||||
virtual ~nsTextEditor();
|
||||
|
||||
//Initialization
|
||||
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Methods that are duplicates of nsEditor -- exposed here for convenience
|
||||
// Editing Operations
|
||||
NS_IMETHOD SetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
NS_IMETHOD GetTextProperty(nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAny, PRBool &aAll);
|
||||
NS_IMETHOD RemoveTextProperty(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
NS_IMETHOD DeleteSelection(nsIEditor::ESelectionCollapseDirection aAction);
|
||||
NS_IMETHOD InsertText(const nsString& aStringToInsert);
|
||||
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
|
||||
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);
|
||||
NS_IMETHOD InsertBreak();
|
||||
NS_IMETHOD CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode);
|
||||
// This method sets background of the page (the body tag)
|
||||
NS_IMETHOD SetBackgroundColor(const nsString& aColor);
|
||||
|
||||
// Transaction control
|
||||
NS_IMETHOD EnableUndo(PRBool aEnable);
|
||||
NS_IMETHOD Undo(PRUint32 aCount);
|
||||
NS_IMETHOD CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
NS_IMETHOD Redo(PRUint32 aCount);
|
||||
NS_IMETHOD CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
NS_IMETHOD BeginTransaction();
|
||||
NS_IMETHOD EndTransaction();
|
||||
|
||||
// Selection and navigation -- exposed here for convenience
|
||||
NS_IMETHOD MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD BeginningOfDocument();
|
||||
NS_IMETHOD EndOfDocument();
|
||||
NS_IMETHOD ScrollUp(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollDown(nsIAtom *aIncrement);
|
||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
|
||||
|
||||
// file handling
|
||||
NS_IMETHOD Save();
|
||||
NS_IMETHOD SaveAs(PRBool aSavingCopy);
|
||||
|
||||
// cut, copy & paste
|
||||
NS_IMETHOD Cut();
|
||||
NS_IMETHOD Copy();
|
||||
NS_IMETHOD Paste();
|
||||
NS_IMETHOD PasteAsQuotation();
|
||||
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
|
||||
|
||||
// Input/Output
|
||||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aRangeList);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
// Plain text wrapping control
|
||||
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
|
||||
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn);
|
||||
|
||||
// Miscellaneous
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||
|
||||
// Logging methods
|
||||
|
||||
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
|
||||
NS_IMETHOD StopLogging();
|
||||
|
||||
// End of methods implemented in nsEditor
|
||||
//=============================================================
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// file handling utils
|
||||
|
||||
NS_IMETHOD SaveDocument(PRBool saveAs, PRBool saveCopy);
|
||||
|
||||
// rules initialization
|
||||
|
||||
virtual void InitRules();
|
||||
|
||||
// Utility Methods
|
||||
|
||||
/** returns the PRE elements that bounds the content of the text document
|
||||
* @param domdoc The text document
|
||||
*/
|
||||
nsCOMPtr<nsIDOMElement> FindPreElement();
|
||||
|
||||
/** content-based query returns PR_TRUE if <aProperty aAttribute=aValue> effects aNode
|
||||
* If <aProperty aAttribute=aValue> contains aNode,
|
||||
* but <aProperty aAttribute=SomeOtherValue> also contains aNode and the second is
|
||||
* more deeply nested than the first, then the first does not effect aNode.
|
||||
*
|
||||
* @param aNode The target of the query
|
||||
* @param aProperty The property that we are querying for
|
||||
* @param aAttribute The attribute of aProperty, example: color in <FONT color="blue">
|
||||
* May be null.
|
||||
* @param aValue The value of aAttribute, example: blue in <FONT color="blue">
|
||||
* May be null. Ignored if aAttribute is null.
|
||||
* @param aIsSet [OUT] PR_TRUE if <aProperty aAttribute=aValue> effects aNode.
|
||||
* @param aStyleNode [OUT] set to the node representing <aProperty aAttribute=aValue>, if found.
|
||||
* null if aIsSet is returned as PR_FALSE;
|
||||
*/
|
||||
virtual void IsTextPropertySetByContent(nsIDOMNode *aNode,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue,
|
||||
PRBool &aIsSet,
|
||||
nsIDOMNode **aStyleNode) const;
|
||||
|
||||
/** style-based query returns PR_TRUE if (aProperty, aAttribute) is set in aSC.
|
||||
* WARNING: not well tested yet since we don't do style-based queries anywhere.
|
||||
*/
|
||||
virtual void IsTextStyleSet(nsIStyleContext *aSC,
|
||||
nsIAtom *aProperty,
|
||||
const nsString *aAttributes,
|
||||
PRBool &aIsSet) const;
|
||||
|
||||
/** Moves the content between (aNode, aStartOffset) and (aNode, aEndOffset)
|
||||
* into aNewParentNode, splitting aNode as necessary to maintain the relative
|
||||
* position of all leaf content.
|
||||
* @param aNode The node whose content we're repositioning.
|
||||
* aNode can be either a text node or a container node.
|
||||
* @param aNewParentNode The node that will be the repositioned contents' parent.
|
||||
* The caller is responsible for allocating aNewParentNode
|
||||
* @param aStartOffset The start offset of the content of aNode
|
||||
* @param aEndOffset The end offset of the content of aNode.
|
||||
*/
|
||||
NS_IMETHOD MoveContentOfNodeIntoNewParent(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aNewParentNode,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset);
|
||||
|
||||
/** Moves the content between (aStartNode, aStartOffset) and (aEndNode, aEndOffset)
|
||||
* into aNewParentNode, splitting aStartNode and aEndNode as necessary to maintain
|
||||
* the relative position of all leaf content.
|
||||
* The content between the two endpoints MUST be "contiguous" in the sense that
|
||||
* it is all in the same block. Another way of saying this is all content nodes
|
||||
* between aStartNode and aEndNode must be inline.
|
||||
* @see IntermediateNodesAreInline
|
||||
*
|
||||
* @param aStartNode The left node, can be either a text node or a container node.
|
||||
* @param aStartOffset The start offset in the content of aStartNode
|
||||
* @param aEndNode The right node, can be either a text node or a container node.
|
||||
* @param aEndOffset The end offset in the content of aEndNode.
|
||||
* @param aGrandParentNode The common ancestor of aStartNode and aEndNode.
|
||||
* aGrandParentNode will be the parent of aNewParentNode.
|
||||
* @param aNewParentNode The node that will be the repositioned contents' parent.
|
||||
* The caller is responsible for allocating aNewParentNode
|
||||
*/
|
||||
NS_IMETHOD MoveContiguousContentIntoNewParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aGrandParentNode,
|
||||
nsIDOMNode *aNewParentNode);
|
||||
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD SetTextPropertiesForNodeWithDifferentParents(nsIDOMRange *aRange,
|
||||
nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNode(nsIDOMNode *aNode,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD RemoveTextPropertiesForNodeWithDifferentParents(nsIDOMNode *aStartNode,
|
||||
PRInt32 aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMNode *aParent,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute);
|
||||
|
||||
NS_IMETHOD SetTypeInStateForProperty(TypeInState &aTypeInState,
|
||||
nsIAtom *aPropName,
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
void GetTextSelectionOffsetsForRange(nsIDOMSelection *aSelection,
|
||||
nsIDOMNode **aParent,
|
||||
PRInt32 &aStartOffset,
|
||||
PRInt32 &aEndOffset);
|
||||
|
||||
void ResetTextSelectionForRange(nsIDOMNode *aParent,
|
||||
PRInt32 aStartOffset,
|
||||
PRInt32 aEndOffset,
|
||||
nsIDOMSelection *aSelection);
|
||||
|
||||
/** returns the absolute position of the end points of aSelection
|
||||
* in the document as a text stream.
|
||||
*/
|
||||
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
|
||||
PRInt32 &aStartOffset,
|
||||
PRInt32 &aEndOffset);
|
||||
|
||||
|
||||
TypeInState *GetTypeInState();
|
||||
|
||||
/** simple utility to handle any error with event listener allocation or registration */
|
||||
void HandleEventListenerError();
|
||||
|
||||
// this overrides the base class implementation. It is not exported in nsITextEditor.
|
||||
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
|
||||
|
||||
// Data members
|
||||
protected:
|
||||
TypeInState *mTypeInState;
|
||||
nsTextEditRules *mRules;
|
||||
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mTextListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mCompositionListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
|
||||
PRBool mIsComposing;
|
||||
PRInt32 mMaxTextLength;
|
||||
PRUint32 mWrapColumn;
|
||||
|
||||
// friends
|
||||
friend class nsTextEditRules;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //nsTextEditor_h__
|
||||
|
||||
2760
mozilla/editor/composer/src/nsEditorShell.cpp
Normal file
2760
mozilla/editor/composer/src/nsEditorShell.cpp
Normal file
File diff suppressed because it is too large
Load Diff
338
mozilla/editor/composer/src/nsEditorShell.h
Normal file
338
mozilla/editor/composer/src/nsEditorShell.h
Normal file
@@ -0,0 +1,338 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsEditorShell_h___
|
||||
#define nsEditorShell_h___
|
||||
|
||||
//#include "nsAppCores.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nsIEditorShell.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#ifdef NECKO
|
||||
#include "nsIPrompt.h"
|
||||
#else
|
||||
#include "nsINetSupport.h"
|
||||
#endif
|
||||
#include "nsIStreamObserver.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsTextServicesCID.h"
|
||||
#include "nsIEditorSpellCheck.h"
|
||||
#include "nsISpellChecker.h"
|
||||
#include "nsInterfaceState.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
class nsIBrowserWindow;
|
||||
class nsIWebShell;
|
||||
class nsIScriptContext;
|
||||
class nsIDOMWindow;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMNode;
|
||||
class nsIURI;
|
||||
class nsIWebShellWindow;
|
||||
class nsIPresShell;
|
||||
class nsIOutputStream;
|
||||
class nsISupportsArray;
|
||||
|
||||
|
||||
#define NS_EDITORSHELL_CID \
|
||||
{ /* {} */ \
|
||||
0x9afff72b, 0xca9a, 0x11d2, \
|
||||
{ 0x96, 0xc9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsEditorShell:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsEditorShell : public nsIEditorShell,
|
||||
public nsIEditorSpellCheck,
|
||||
public nsIDocumentLoaderObserver
|
||||
{
|
||||
public:
|
||||
|
||||
nsEditorShell();
|
||||
virtual ~nsEditorShell();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD Init();
|
||||
// NS_IMETHOD GetId(nsString& aId); // { return nsBaseAppCore::GetId(aId); }
|
||||
// NS_IMETHOD SetDocumentCharset(const nsString& aCharset); // { return nsBaseAppCore::SetDocumentCharset(aCharset); }
|
||||
|
||||
|
||||
/* nsIEditorShell interface */
|
||||
|
||||
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
||||
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||
|
||||
NS_IMETHOD GetDocumentModified(PRBool *aDocumentModified);
|
||||
|
||||
NS_IMETHOD GetWrapColumn(PRInt32 *aWrapColumn);
|
||||
NS_IMETHOD SetWrapColumn(PRInt32 aWrapColumn);
|
||||
|
||||
NS_IMETHOD SetEditorType(const PRUnichar *editorType);
|
||||
|
||||
NS_IMETHOD SetToolbarWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD SetContentWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD SetWebShellWindow(nsIDOMWindow *win);
|
||||
NS_IMETHOD LoadUrl(const PRUnichar *url);
|
||||
NS_IMETHOD RegisterDocumentStateListener(nsIDocumentStateListener *docListener);
|
||||
NS_IMETHOD UnregisterDocumentStateListener(nsIDocumentStateListener *docListener);
|
||||
|
||||
/* void NewWindow (); */
|
||||
NS_IMETHOD NewWindow();
|
||||
NS_IMETHOD Open();
|
||||
NS_IMETHOD Save();
|
||||
NS_IMETHOD SaveAs();
|
||||
NS_IMETHOD CloseWindow();
|
||||
NS_IMETHOD Print();
|
||||
NS_IMETHOD Exit();
|
||||
|
||||
NS_IMETHOD Undo();
|
||||
NS_IMETHOD Redo();
|
||||
NS_IMETHOD Cut();
|
||||
NS_IMETHOD Copy();
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
NS_IMETHOD PasteAsQuotation();
|
||||
NS_IMETHOD PasteAsCitedQuotation(const PRUnichar *cite);
|
||||
NS_IMETHOD InsertAsQuotation(const PRUnichar *quotedText);
|
||||
NS_IMETHOD InsertAsCitedQuotation(const PRUnichar *quotedText, const PRUnichar *cite);
|
||||
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD DeleteSelection(PRInt32 direction);
|
||||
|
||||
/* void Find (); */
|
||||
NS_IMETHOD Find();
|
||||
NS_IMETHOD FindNext();
|
||||
|
||||
/* void InsertText (in wstring textToInsert); */
|
||||
NS_IMETHOD InsertText(const PRUnichar *textToInsert);
|
||||
NS_IMETHOD InsertSource(const PRUnichar *sourceToInsert);
|
||||
NS_IMETHOD InsertBreak();
|
||||
NS_IMETHOD InsertList(const PRUnichar *listType);
|
||||
|
||||
/* void Indent (in string indent); */
|
||||
NS_IMETHOD Indent(const PRUnichar *indent);
|
||||
NS_IMETHOD Align(const PRUnichar *align);
|
||||
|
||||
/* nsIDOMElement GetSelectedElement (in wstring tagName); */
|
||||
NS_IMETHOD GetSelectedElement(const PRUnichar *tagName, nsIDOMElement **_retval);
|
||||
NS_IMETHOD GetElementOrParentByTagName(const PRUnichar *tagName, nsIDOMNode *aNode, nsIDOMElement **_retval);
|
||||
NS_IMETHOD CreateElementWithDefaults(const PRUnichar *tagName, nsIDOMElement **_retval);
|
||||
NS_IMETHOD InsertElement(nsIDOMElement *element, PRBool deleteSelection);
|
||||
NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement);
|
||||
NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement *anchorElement);
|
||||
NS_IMETHOD SelectElement(nsIDOMElement *element);
|
||||
NS_IMETHOD SetSelectionAfterElement(nsIDOMElement *element);
|
||||
|
||||
/* Table insert and delete methods. Done relative to selected cell or
|
||||
cell containing the selection anchor */
|
||||
NS_IMETHOD InsertTableCell(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD InsertTableRow(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD InsertTableColumn(PRInt32 aNumber, PRBool bAfter);
|
||||
NS_IMETHOD DeleteTable();
|
||||
NS_IMETHOD DeleteTableCell(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableRow(PRInt32 aNumber);
|
||||
NS_IMETHOD DeleteTableColumn(PRInt32 aNumber);
|
||||
NS_IMETHOD JoinTableCells();
|
||||
/** Make table "rectangular" -- fill in all missing cellmap locations
|
||||
* If aTable is null, it uses table enclosing the selection anchor
|
||||
*/
|
||||
NS_IMETHOD NormalizeTable(nsIDOMElement *aTable);
|
||||
|
||||
/* Get the row and col indexes in layout's cellmap */
|
||||
NS_IMETHOD GetRowIndex(nsIDOMElement *aCell, PRInt32 *_retval);
|
||||
NS_IMETHOD GetColumnIndex(nsIDOMElement *aCell, PRInt32 *_retval);
|
||||
/** Get the number of rows in a table from the layout's cellmap */
|
||||
NS_IMETHOD GetTableRowCount(nsIDOMElement *aTable, PRInt32 *_retval);
|
||||
/** Get the number of columns in a table from the layout's cellmap */
|
||||
NS_IMETHOD GetTableColumnCount(nsIDOMElement *aTable, PRInt32 *_retval);
|
||||
|
||||
/* Get a cell and associated data from the layout frame based on cell map coordinates (0 index) */
|
||||
NS_IMETHOD GetCellAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex, nsIDOMElement **_retval);
|
||||
/* Note that the return param in the IDL must be the LAST out param here (_retval) */
|
||||
NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
|
||||
PRInt32 *aStartRowIndex, PRInt32 *aStartColIndex,
|
||||
PRInt32 *aRowSpan, PRInt32 *aColSpan, PRBool *aIsSelected, nsIDOMElement **_retval);
|
||||
|
||||
/* Get list of embedded objects, e.g. for mail compose */
|
||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray **aObjectArray);
|
||||
|
||||
/* void SetParagraphFormat (in string value); */
|
||||
NS_IMETHOD SetParagraphFormat(PRUnichar *value);
|
||||
NS_IMETHOD GetParagraphFormat(PRUnichar * *aParagraphFormat);
|
||||
|
||||
/* void SetTextProperty (in string prop, in string attr, in string value); */
|
||||
NS_IMETHOD SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value);
|
||||
NS_IMETHOD GetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value, PRBool *firstHas, PRBool *anyHas, PRBool *allHas);
|
||||
NS_IMETHOD RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr);
|
||||
|
||||
/* void SetBodyAttribute (in string attr, in string value); */
|
||||
NS_IMETHOD SetBodyAttribute(const PRUnichar *attr, const PRUnichar *value);
|
||||
NS_IMETHOD SetBackgroundColor(const PRUnichar *color);
|
||||
|
||||
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
||||
|
||||
/* Get the contents, for output or other uses */
|
||||
NS_IMETHOD GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs);
|
||||
|
||||
/* Debugging: dump content tree to stdout */
|
||||
NS_IMETHOD DumpContentTree();
|
||||
|
||||
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
||||
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
||||
|
||||
/* void BeginBatchChanges (); */
|
||||
NS_IMETHOD BeginBatchChanges();
|
||||
NS_IMETHOD EndBatchChanges();
|
||||
|
||||
/* void RunUnitTests (); */
|
||||
NS_IMETHOD RunUnitTests();
|
||||
|
||||
/* void BeginLogging (); */
|
||||
NS_IMETHOD StartLogging(nsIFileSpec *logFile);
|
||||
NS_IMETHOD StopLogging();
|
||||
|
||||
|
||||
/* Spell check interface */
|
||||
NS_IMETHOD StartSpellChecking(PRUnichar **_retval);
|
||||
NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval);
|
||||
NS_IMETHOD GetSuggestedWord(PRUnichar **_retval);
|
||||
NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval);
|
||||
NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences);
|
||||
NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word);
|
||||
NS_IMETHOD GetPersonalDictionary();
|
||||
NS_IMETHOD GetPersonalDictionaryWord(PRUnichar **_retval);
|
||||
NS_IMETHOD AddWordToDictionary(const PRUnichar *word);
|
||||
NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word);
|
||||
NS_IMETHOD CloseSpellChecking();
|
||||
|
||||
|
||||
// nsIDocumentLoaderObserver
|
||||
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aCommand);
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIURI *aUrl, PRInt32 aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver);
|
||||
#else
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRInt32 aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aContentType,
|
||||
nsIContentViewer* aViewer);
|
||||
#else
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsIContentViewer* aViewer);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
#else
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, nsString& aMsg);
|
||||
#else
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsString& aMsg);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIURI* aURL, PRInt32 aStatus);
|
||||
#else
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRInt32 aStatus);
|
||||
#endif // NECKO
|
||||
|
||||
#ifndef NECKO
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIURI *aURL,
|
||||
const char *aContentType,
|
||||
const char *aCommand );
|
||||
#else
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
const char *aContentType,
|
||||
const char *aCommand );
|
||||
#endif // NECKO
|
||||
|
||||
protected:
|
||||
nsIDOMWindow *mToolbarWindow; // weak reference
|
||||
nsIDOMWindow *mContentWindow; // weak reference
|
||||
|
||||
nsIWebShellWindow *mWebShellWin; // weak reference
|
||||
nsIWebShell *mWebShell; // weak reference
|
||||
nsIWebShell *mContentAreaWebShell; // weak reference
|
||||
|
||||
typedef enum {
|
||||
eUninitializedEditorType = 0,
|
||||
ePlainTextEditorType = 1,
|
||||
eHTMLTextEditorType = 2
|
||||
} EEditorType;
|
||||
|
||||
nsIPresShell* GetPresShellFor(nsIWebShell* aWebShell);
|
||||
NS_IMETHOD DoEditorMode(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
|
||||
NS_IMETHOD InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
NS_IMETHOD TransferDocumentStateListeners();
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
|
||||
NS_IMETHOD CreateWindowWithURL(const char* urlStr);
|
||||
NS_IMETHOD PrepareDocumentForEditing(nsIURI *aUrl);
|
||||
NS_IMETHOD DoFind(PRBool aFindNext);
|
||||
|
||||
// this returns an AddReffed nsIScriptContext. You must relase it.
|
||||
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
|
||||
|
||||
nsString mEnableScript;
|
||||
nsString mDisableScript;
|
||||
|
||||
EEditorType mEditorType;
|
||||
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
|
||||
nsCOMPtr<nsIHighLevelHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
|
||||
|
||||
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
||||
|
||||
nsInterfaceState* mStateMaintainer; // we hold the owning ref to this.
|
||||
|
||||
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
|
||||
|
||||
nsCOMPtr<nsISpellChecker> mSpellChecker;
|
||||
nsStringArray mSuggestedWordList;
|
||||
PRInt32 mSuggestedWordIndex;
|
||||
NS_IMETHOD DeleteSuggestedWordList();
|
||||
nsStringArray mDictionaryList;
|
||||
PRInt32 mDictionaryIndex;
|
||||
|
||||
// this is a holding pen for doc state listeners. They will be registered with
|
||||
// the editor when that gets created.
|
||||
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
|
||||
};
|
||||
|
||||
#endif // nsEditorShell_h___
|
||||
60
mozilla/editor/composer/src/nsEditorShellFactory.h
Normal file
60
mozilla/editor/composer/src/nsEditorShellFactory.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsEditorAppCoreFactory_h___
|
||||
#define nsEditorAppCoreFactory_h___
|
||||
|
||||
//#include "nscore.h"
|
||||
//#include "nsString.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsEditorAppCoreFactory:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsEditorShellFactoryImpl : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsEditorShellFactoryImpl(const nsCID &aClass, const char* className, const char* progID);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
PRBool CanUnload(void);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID& aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~nsEditorShellFactoryImpl();
|
||||
|
||||
protected:
|
||||
nsCID mClassID;
|
||||
const char* mClassName;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
nsresult
|
||||
GetEditorShellFactory(nsIFactory **aFactory, const nsCID &aClass, const char *aClassName, const char *aProgID);
|
||||
|
||||
#endif // nsEditorAppCoreFactory_h___
|
||||
300
mozilla/editor/composer/src/nsInterfaceState.cpp
Normal file
300
mozilla/editor/composer/src/nsInterfaceState.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDiskDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHighLevelHTMLEditor.h"
|
||||
|
||||
#include "nsInterfaceState.h"
|
||||
|
||||
|
||||
|
||||
nsInterfaceState::nsInterfaceState()
|
||||
: mEditor(nsnull)
|
||||
, mWebShell(nsnull)
|
||||
, mBoldState(eStateUninitialized)
|
||||
, mItalicState(eStateUninitialized)
|
||||
, mUnderlineState(eStateUninitialized)
|
||||
, mDirtyState(eStateUninitialized)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsInterfaceState::~nsInterfaceState()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsInterfaceState);
|
||||
NS_IMPL_RELEASE(nsInterfaceState);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = nsnull;
|
||||
if (aIID.Equals(nsIDOMSelectionListener::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsIDOMSelectionListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsIDocumentStateListener::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsIDocumentStateListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsISupports *)(nsIDOMSelectionListener*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::Init(nsIHighLevelHTMLEditor* aEditor, nsIWebShell *aChromeWebShell)
|
||||
{
|
||||
if (!aEditor)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!aChromeWebShell)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
mEditor = aEditor; // no addreffing here
|
||||
mWebShell = aChromeWebShell;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentCreated()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentWillBeDestroyed()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifyDocumentStateChanged(PRBool aNowDirty)
|
||||
{
|
||||
// update document modified. We should have some other notifications for this too.
|
||||
return UpdateDirtyState(aNowDirty);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifySelectionChanged()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// we don't really care if any of these fail.
|
||||
|
||||
// update bold
|
||||
rv = UpdateTextState("b", "Editor:Style:IsBold", "bold", mBoldState);
|
||||
// update italic
|
||||
rv = UpdateTextState("i", "Editor:Style:IsItalic", "italic", mItalicState);
|
||||
// update underline
|
||||
rv = UpdateTextState("u", "Editor:Style:IsUnderline", "underline", mUnderlineState);
|
||||
|
||||
// udpate the font face
|
||||
rv = UpdateFontFace("Editor:Font:Face", "font", mFontString);
|
||||
|
||||
// update the paragraph format popup
|
||||
rv = UpdateParagraphState("Editor:Paragraph:Format", "format", mParagraphFormat);
|
||||
|
||||
// update the list buttons
|
||||
rv = UpdateListState("Editor:Paragraph:List", "ol");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat)
|
||||
{
|
||||
nsStringArray tagList;
|
||||
|
||||
mEditor->GetParagraphStyle(&tagList);
|
||||
|
||||
PRInt32 numTags = tagList.Count();
|
||||
if (numTags > 0)
|
||||
{
|
||||
nsAutoString thisTag;
|
||||
tagList.StringAt(0, thisTag);
|
||||
if (thisTag != mParagraphFormat)
|
||||
{
|
||||
nsresult rv = SetNodeAttribute(observerName, attributeName, thisTag);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mParagraphFormat = thisTag;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateListState(const char* observerName, const char* tagName)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsCOMPtr<nsIDOMSelection> domSelection;
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
editor->GetSelection(getter_AddRefs(domSelection));
|
||||
}
|
||||
|
||||
nsAutoString tagStr(tagName);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
if (domSelection)
|
||||
domSelection->GetAnchorNode(getter_AddRefs(domNode));
|
||||
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
rv = mEditor->GetElementOrParentByTagName(tagStr, domNode, getter_AddRefs(parentElement));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateFontFace(const char* observerName, const char* attributeName, nsString& ioFontString)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
nsAutoString faceStr("face");
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(tagName));
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
PRBool &behaviour = allOfSelectionHasProp; // change this to alter the behaviour
|
||||
if (behaviour != ioState)
|
||||
{
|
||||
rv = SetNodeAttribute(observerName, attributeName, behaviour ? "true" : "false");
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
ioState = behaviour;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
|
||||
{
|
||||
if (mDirtyState != aNowDirty)
|
||||
{
|
||||
nsresult rv = SetNodeAttribute("Editor:Document:Dirty", "dirty", aNowDirty ? "true" : "false");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mDirtyState = aNowDirty;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!mWebShell)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = mWebShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocument> chromeDoc;
|
||||
rv = docViewer->GetDocument(*getter_AddRefs(chromeDoc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(chromeDoc, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = xulDoc->GetElementById( nodeID, getter_AddRefs(elem) );
|
||||
if (NS_FAILED(rv) || !elem) return rv;
|
||||
|
||||
return elem->SetAttribute(attributeName, newValue);
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_NewInterfaceState(nsIHighLevelHTMLEditor* aEditor, nsIWebShell* aWebShell, nsIDOMSelectionListener** aInstancePtrResult)
|
||||
{
|
||||
nsInterfaceState* newThang = new nsInterfaceState;
|
||||
if (!newThang)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aInstancePtrResult = nsnull;
|
||||
nsresult rv = newThang->Init(aEditor, aWebShell);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete newThang;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return newThang->QueryInterface(nsIDOMSelectionListener::GetIID(), (void **)aInstancePtrResult);
|
||||
}
|
||||
90
mozilla/editor/composer/src/nsInterfaceState.h
Normal file
90
mozilla/editor/composer/src/nsInterfaceState.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsInterfaceState_h__
|
||||
#define nsInterfaceState_h__
|
||||
|
||||
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#include "nsIDocumentStateListener.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
class nsIHighLevelHTMLEditor;
|
||||
|
||||
// class responsible for communicating changes in local state back to the UI.
|
||||
// This is currently somewhat tied to a given XUL UI implementation
|
||||
|
||||
class nsInterfaceState : public nsIDOMSelectionListener,
|
||||
public nsIDocumentStateListener
|
||||
{
|
||||
public:
|
||||
|
||||
nsInterfaceState();
|
||||
virtual ~nsInterfaceState();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(nsIHighLevelHTMLEditor* aEditor, nsIWebShell *aChromeWebShell);
|
||||
|
||||
// nsIDOMSelectionListener interface
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
// nsIDocumentStateListener interface
|
||||
NS_IMETHOD NotifyDocumentCreated();
|
||||
NS_IMETHOD NotifyDocumentWillBeDestroyed();
|
||||
NS_IMETHOD NotifyDocumentStateChanged(PRBool aNowDirty);
|
||||
|
||||
protected:
|
||||
|
||||
enum {
|
||||
eStateUninitialized = -1,
|
||||
eStateOff = PR_FALSE,
|
||||
eStateOn = PR_TRUE
|
||||
};
|
||||
|
||||
nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue);
|
||||
|
||||
nsresult UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat);
|
||||
nsresult UpdateListState(const char* observerName, const char* tagName);
|
||||
nsresult UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState);
|
||||
nsresult UpdateFontFace(const char* observerName, const char* attributeName, nsString& ioFontString);
|
||||
nsresult UpdateDirtyState(PRBool aNowDirty);
|
||||
|
||||
// this class should not hold references to the editor or editorShell. Doing
|
||||
// so would result in cirular reference chains.
|
||||
|
||||
nsIHighLevelHTMLEditor* mEditor; // the HTML editor
|
||||
nsIWebShell* mWebShell; // web shell for the chrome area
|
||||
|
||||
// current state
|
||||
PRInt8 mBoldState;
|
||||
PRInt8 mItalicState;
|
||||
PRInt8 mUnderlineState;
|
||||
|
||||
PRInt8 mDirtyState;
|
||||
|
||||
nsString mParagraphFormat;
|
||||
nsString mFontString;
|
||||
nsString mListTag; // contains "" for none, "ol" or "ul"
|
||||
|
||||
};
|
||||
|
||||
extern "C" nsresult NS_NewInterfaceState(nsIHighLevelHTMLEditor* aEditor, nsIWebShell* aWebShell, nsIDOMSelectionListener** aInstancePtrResult);
|
||||
|
||||
#endif // nsInterfaceState_h__
|
||||
33
mozilla/editor/guimgr/Makefile.in
Normal file
33
mozilla/editor/guimgr/Makefile.in
Normal file
@@ -0,0 +1,33 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
BIN
mozilla/editor/guimgr/macbuild/EditorGuiManager.mcp
Normal file
BIN
mozilla/editor/guimgr/macbuild/EditorGuiManager.mcp
Normal file
Binary file not shown.
3
mozilla/editor/guimgr/macbuild/EditorGuiManager.toc
Normal file
3
mozilla/editor/guimgr/macbuild/EditorGuiManager.toc
Normal file
@@ -0,0 +1,3 @@
|
||||
# target: EditorGuiManagerDebug.shlb
|
||||
mozilla/editor/guimgr/src/nsEditGuiManager.cpp
|
||||
mozilla/editor/guimgr/src/nsGuiManagerFactory.cpp
|
||||
25
mozilla/editor/guimgr/makefile.win
Normal file
25
mozilla/editor/guimgr/makefile.win
Normal file
@@ -0,0 +1,25 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
# add "tests" after makefile is finished
|
||||
|
||||
DIRS=public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
20
mozilla/editor/guimgr/public/MANIFEST
Normal file
20
mozilla/editor/guimgr/public/MANIFEST
Normal file
@@ -0,0 +1,20 @@
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist:editor directory
|
||||
#
|
||||
|
||||
nsIEditGuiManager.h
|
||||
nsIGuiManagerFactory.h
|
||||
36
mozilla/editor/guimgr/public/Makefile.in
Normal file
36
mozilla/editor/guimgr/public/Makefile.in
Normal file
@@ -0,0 +1,36 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
EXPORTS = \
|
||||
nsIEditGuiManager.h \
|
||||
nsIGuiManagerFactory.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = editor
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
29
mozilla/editor/guimgr/public/makefile.win
Normal file
29
mozilla/editor/guimgr/public/makefile.win
Normal file
@@ -0,0 +1,29 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
EXPORTS = \
|
||||
nsIGuiManagerFactory.h \
|
||||
nsIEditGuiManager.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = editor
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
41
mozilla/editor/guimgr/public/nsIEditGuiManager.h
Normal file
41
mozilla/editor/guimgr/public/nsIEditGuiManager.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIEditGuiManager_h__
|
||||
#define nsIEditGuiManager_h__
|
||||
#include "nsISupports.h"
|
||||
|
||||
/*
|
||||
Gui Manager interface to outside world
|
||||
*/
|
||||
|
||||
#define NS_IEDITGUIMANAGER_IID \
|
||||
{ /* DD514F80-8BA7-11d2-9821-00805F8AA8B8 */ \
|
||||
0xdd514f80, 0x8ba7, 0x11d2, \
|
||||
{ 0x98, 0x21, 0x0, 0x80, 0x5f, 0x8a, 0xa8, 0xb8 } }
|
||||
|
||||
/**
|
||||
* A Gui manager specific interface.
|
||||
*/
|
||||
class nsIEditGuiManager : public nsISupports{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIEditGuiManager_h__
|
||||
|
||||
42
mozilla/editor/guimgr/public/nsIGuiManagerFactory.h
Normal file
42
mozilla/editor/guimgr/public/nsIGuiManagerFactory.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIGuiManagerFactory_h__
|
||||
#define nsIGuiManagerFactory_h__
|
||||
#include "nsISupports.h"
|
||||
|
||||
/*
|
||||
Gui Manager interface to outside world
|
||||
*/
|
||||
|
||||
#define NS_IGUIMANAGERFACTORY_IID \
|
||||
{ /* 6279AC00-8BD7-11d2-9821-00805F8AA8B8*/ \
|
||||
0x6279ac00, 0x8bd7, 0x11d2, \
|
||||
{ 0x98, 0x21, 0x0, 0x80, 0x5f, 0x8a, 0xa8, 0xb8 } }
|
||||
|
||||
|
||||
/**
|
||||
* A Gui manager specific interface.
|
||||
*/
|
||||
class nsIGuiManagerFactory : public nsISupports{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIGuiManagerFactory_h__
|
||||
|
||||
44
mozilla/editor/guimgr/src/Makefile.in
Normal file
44
mozilla/editor/guimgr/src/Makefile.in
Normal file
@@ -0,0 +1,44 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../../..
|
||||
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = editguimgr
|
||||
|
||||
CPPSRCS = \
|
||||
nsEditGuiManager.cpp \
|
||||
nsGuiManagerFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
MODULE = editguimgr
|
||||
|
||||
REQUIRES = xpcom
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
TARGET = $(LIBARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
test:
|
||||
@echo OS_ARCH = $(OS_ARCH)
|
||||
68
mozilla/editor/guimgr/src/makefile.win
Normal file
68
mozilla/editor/guimgr/src/makefile.win
Normal file
@@ -0,0 +1,68 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
LIBRARY_NAME=editguimgr
|
||||
|
||||
CPPSRCS = \
|
||||
nsEditGuiManager.cpp \
|
||||
nsGuiManagerFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsEditGuiManager.obj \
|
||||
.\$(OBJDIR)\nsGuiManagerFactory.obj \
|
||||
$(NULL)
|
||||
|
||||
MODULE=editguimgr
|
||||
|
||||
REQUIRES=xpcom base raptor
|
||||
|
||||
LINCS=-I$(PUBLIC)\editor \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\guimgr \
|
||||
-I$(PUBLIC)\base \
|
||||
-I$(PUBLIC)\raptor
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = editguimgr
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
# These are the libraries we need to link with to create the dll
|
||||
LLIBS=$(DIST)\lib\xpcom.lib
|
||||
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\components\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user