зеркало из https://github.com/mozilla/gecko-dev.git
* the viewer test app now instantiates an nsITextEditor via nsRepository for "Editor mode"
* the TxnMgr is invoked by the editor via nsRepository * editor.h|cpp have been renamed nsEditor.h|cpp for consistency * editorInterfaces.h|cpp have been renamed nsEditorEventListeners.c|hpp * added nsITextEditor.h, nsTextEditor.h|cpp. The text editor is a placeholder for the rules unique to text editing. It invokes the nsIEditor to do core editing operations. * reworked nsIEditor and related interfaces as per emerging design. * nsEditor::BeginTransaction and EndTransaction call nsTransactionManager::BeginBatch and EndBatch.
This commit is contained in:
Родитель
51f4225370
Коммит
1ceedf5abc
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "editor.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
ChangeAttributeTxn::ChangeAttributeTxn()
|
||||
: EditTxn()
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "InsertTextTxn.h"
|
||||
#include "editor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIPresShell.h"
|
||||
|
@ -49,11 +49,8 @@ nsresult InsertTextTxn::Do(void)
|
|||
// advance caret: This requires the presentation shell to get the selection.
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
res = mPresShell->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
// We know mOffset+Length should be there
|
||||
// because we just added that many characters.
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -65,7 +62,11 @@ nsresult InsertTextTxn::Undo(void)
|
|||
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(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,11 @@ include $(DEPTH)/config/autoconf.mk
|
|||
LIBRARY_NAME = ender
|
||||
|
||||
CPPSRCS = \
|
||||
editor.cpp \
|
||||
editorInterfaces.cpp \
|
||||
nsEditor.cpp \
|
||||
nsTextEditor.cpp \
|
||||
nsEditorEventListeners.cpp \
|
||||
nsEditFactory.cpp \
|
||||
nsTextEditFactory.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
EditTxn.cpp \
|
||||
EditAggregateTxn.cpp \
|
||||
|
|
|
@ -21,9 +21,11 @@ IGNORE_MANIFEST=1
|
|||
LIBRARY_NAME=ender
|
||||
|
||||
CPPSRCS = \
|
||||
editor.cpp \
|
||||
editorInterfaces.cpp \
|
||||
nsEditor.cpp \
|
||||
nsTextEditor.cpp \
|
||||
nsEditorEventListeners.cpp \
|
||||
nsEditFactory.cpp \
|
||||
nsTextEditFactory.cpp \
|
||||
EditTxn.cpp \
|
||||
EditAggregateTxn.cpp \
|
||||
ChangeAttributeTxn.cpp \
|
||||
|
@ -38,9 +40,11 @@ CPPSRCS = \
|
|||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\editor.obj \
|
||||
.\$(OBJDIR)\nsEditor.obj \
|
||||
.\$(OBJDIR)\nsTextEditor.obj \
|
||||
.\$(OBJDIR)\nsEditorEventListeners.obj \
|
||||
.\$(OBJDIR)\nsEditFactory.obj \
|
||||
.\$(OBJDIR)\editorInterfaces.obj \
|
||||
.\$(OBJDIR)\nsTextEditFactory.obj \
|
||||
.\$(OBJDIR)\EditTxn.obj \
|
||||
.\$(OBJDIR)\EditAggregateTxn.obj \
|
||||
.\$(OBJDIR)\ChangeAttributeTxn.obj \
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
#include "nsEditFactory.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "editor.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsEditorCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
@ -31,14 +31,14 @@ static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID);
|
|||
|
||||
|
||||
nsresult
|
||||
getEditFactory(nsIFactory **aFactory)
|
||||
GetEditFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
static nsCOMPtr<nsIFactory> g_pNSIFactory;
|
||||
PR_EnterMonitor(getEditorMonitor());
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
if (!g_pNSIFactory)
|
||||
{
|
||||
nsEditFactory *factory = new nsEditFactory(kEditorCID);
|
||||
nsEditFactory *factory = new nsEditFactory(aClass);
|
||||
g_pNSIFactory = factory;
|
||||
if (factory)
|
||||
result = NS_OK;
|
||||
|
|
|
@ -31,7 +31,7 @@ EditFactory that can make an editor
|
|||
*/
|
||||
class nsEditFactory;
|
||||
|
||||
nsresult getEditFactory(nsIFactory **);
|
||||
nsresult GetEditFactory(nsIFactory **aFactory, const nsCID & aClass);
|
||||
|
||||
class nsEditFactory : public nsIFactory {
|
||||
public:
|
||||
|
@ -60,7 +60,7 @@ private:
|
|||
/** getEditFactory
|
||||
* creates an edit factory other CSID supported friend functions here.
|
||||
*/
|
||||
friend nsresult getEditFactory(nsIFactory **);
|
||||
friend nsresult GetEditFactory(nsIFactory **, const nsCID & );
|
||||
const nsCID &mCID;
|
||||
};
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,264 @@
|
|||
/* -*- 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 "prmon.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIContextLoader.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "TransactionFactory.h"
|
||||
#include "nsRepository.h"
|
||||
//#include "nsISelection.h"
|
||||
|
||||
class nsIDOMCharacterData;
|
||||
class nsIDOMRange;
|
||||
class nsIPresShell;
|
||||
class nsIViewManager;
|
||||
class ChangeAttributeTxn;
|
||||
class CreateElementTxn;
|
||||
class DeleteElementTxn;
|
||||
class InsertTextTxn;
|
||||
class DeleteTextTxn;
|
||||
class SplitElementTxn;
|
||||
class JoinElementTxn;
|
||||
class EditAggregateTxn;
|
||||
class nsVoidArray;
|
||||
|
||||
//This is the monitor for the editor.
|
||||
PRMonitor *getEditorMonitor();
|
||||
|
||||
/*
|
||||
struct Properties
|
||||
{
|
||||
Properties (nsIAtom *aPropName, nsIAtom *aValue, PRBool aAppliesToAll);
|
||||
~Properties();
|
||||
|
||||
nsIAtom *mPropName;
|
||||
nsIAtom *mValue;
|
||||
PRBool mAppliesToAll;
|
||||
};
|
||||
|
||||
inline Property::Property(nsIAtom *aPropName, nsIAtom *aValue, PRBool aAppliesToAll)
|
||||
{
|
||||
mPropName = aPropName;
|
||||
mPropValue = aPropValue;
|
||||
mAppliesToAll = aAppliesToAll;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
/** 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
|
||||
{
|
||||
private:
|
||||
nsIPresShell *mPresShell;
|
||||
nsIViewManager *mViewManager;
|
||||
PRUint32 mUpdateCount;
|
||||
nsCOMPtr<nsIDOMDocument> mDoc;
|
||||
nsCOMPtr<nsITransactionManager> mTxnMgr;
|
||||
|
||||
|
||||
friend PRBool NSCanUnload(void);
|
||||
static PRInt32 gInstanceCount;
|
||||
|
||||
public:
|
||||
/** 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();
|
||||
|
||||
/*BEGIN nsIEdieditor for more details*/
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell);
|
||||
|
||||
virtual nsresult GetDocument(nsIDOMDocument **aDoc);
|
||||
|
||||
virtual nsresult SetProperties(nsVoidArray *aPropList);
|
||||
|
||||
virtual nsresult GetProperties(nsVoidArray *aPropList);
|
||||
|
||||
virtual nsresult SetAttribute(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue);
|
||||
|
||||
virtual nsresult GetAttributeValue(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
nsString& aResultValue,
|
||||
PRBool& aResultIsSet);
|
||||
|
||||
virtual nsresult RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute);
|
||||
|
||||
virtual nsresult CreateNode(const nsString& aTag,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition);
|
||||
|
||||
virtual nsresult InsertNode(nsIDOMNode * aNode,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition);
|
||||
virtual nsresult InsertText(const nsString& aStringToInsert);
|
||||
|
||||
virtual nsresult DeleteNode(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aChild);
|
||||
|
||||
virtual nsresult DeleteSelection(nsIEditor::Direction aDir);
|
||||
|
||||
virtual nsresult SplitNode(nsIDOMNode * aExistingRightNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMNode * aNewLeftNode,
|
||||
nsIDOMNode * aParent);
|
||||
|
||||
virtual nsresult JoinNodes(nsIDOMNode * aNodeToKeep,
|
||||
nsIDOMNode * aNodeToJoin,
|
||||
nsIDOMNode * aParent,
|
||||
PRBool aNodeToKeepIsFirst);
|
||||
|
||||
virtual nsresult InsertBreak(PRBool aCtrlKey);
|
||||
|
||||
virtual nsresult EnableUndo(PRBool aEnable);
|
||||
|
||||
virtual nsresult Do(nsITransaction *aTxn);
|
||||
|
||||
virtual nsresult Undo(PRUint32 aCount);
|
||||
|
||||
virtual nsresult CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
|
||||
virtual nsresult Redo(PRUint32 aCount);
|
||||
|
||||
virtual nsresult CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
|
||||
virtual nsresult BeginTransaction();
|
||||
|
||||
virtual nsresult EndTransaction();
|
||||
|
||||
/*END nsIEditor interfaces*/
|
||||
|
||||
|
||||
/*BEGIN public methods unique to nsEditor. These will get moved to an interface
|
||||
if they survive.
|
||||
*/
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
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 nsIDOMNode *aStartNode is the node to start looking from
|
||||
* @param nsIAtom *aTag is the type of node we are searching for
|
||||
* @param nsIDOMNode **aResult is the node we found, or nsnull if there is none
|
||||
*/
|
||||
nsresult GetFirstNodeOfType(nsIDOMNode *aStartNode, const nsString &aTag, nsIDOMNode **aResult);
|
||||
|
||||
/*END public methods of nsEditor*/
|
||||
|
||||
|
||||
/*BEGIN private methods used by the implementations of the above functions*/
|
||||
protected:
|
||||
virtual nsresult CreateTxnForSetAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForCreateElement(const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aPosition,
|
||||
CreateElementTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteElement(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aElement,
|
||||
DeleteElementTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForInsertText(const nsString & aStringToInsert,
|
||||
InsertTextTxn ** aTxn);
|
||||
|
||||
|
||||
virtual nsresult DeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength,
|
||||
DeleteTextTxn **aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
||||
nsIEditor::Direction aDir,
|
||||
EditAggregateTxn *aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
PRUint32 aOffset,
|
||||
SplitElementTxn **aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
|
||||
nsIDOMNode *aRightNode,
|
||||
JoinElementTxn **aTxn);
|
||||
|
||||
#if 0
|
||||
nsresult CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
||||
#endif
|
||||
|
||||
nsresult GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetRightmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
factory method(s)
|
||||
*/
|
||||
|
||||
nsresult NS_MakeEditorLoader(nsIContextLoader **aResult);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,480 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
#include "nsEditorEventListeners.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
#include "CreateElementTxn.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
||||
|
||||
|
||||
/*
|
||||
* nsTextEditorKeyListener implementation
|
||||
*/
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditorKeyListener)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextEditorKeyListener)
|
||||
|
||||
|
||||
nsTextEditorKeyListener::nsTextEditorKeyListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsTextEditorKeyListener::~nsTextEditorKeyListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::ProcessEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar)
|
||||
{
|
||||
/* This is completely temporary to get this working while I check out Unicode conversion code. */
|
||||
#ifdef XP_MAC
|
||||
if (aChar) {
|
||||
*aChar = (char)aKeyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
#else
|
||||
if (aKeyCode >= 0x41 && aKeyCode <= 0x5A) {
|
||||
if (aIsShift) {
|
||||
*aChar = (char)aKeyCode;
|
||||
}
|
||||
else {
|
||||
*aChar = (char)(aKeyCode + 0x20);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
else if ((aKeyCode >= 0x30 && aKeyCode <= 0x39) || aKeyCode == 0x20) {
|
||||
*aChar = (char)aKeyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
PRUint32 keyCode;
|
||||
PRBool isShift;
|
||||
PRBool ctrlKey;
|
||||
char character;
|
||||
|
||||
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
|
||||
) {
|
||||
PRBool keyProcessed;
|
||||
ProcessShortCutKeys(aKeyEvent, keyProcessed);
|
||||
if (PR_FALSE==keyProcessed)
|
||||
{
|
||||
switch(keyCode) {
|
||||
case nsIDOMEvent::VK_BACK:
|
||||
mEditor->DeleteSelection(nsIEditor::eRTL);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_DELETE:
|
||||
mEditor->DeleteSelection(nsIEditor::eLTR);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_RETURN:
|
||||
// Need to implement creation of either <P> or <BR> nodes.
|
||||
mEditor->InsertBreak(ctrlKey);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsAutoString key;
|
||||
key += character;
|
||||
if (!isShift) {
|
||||
key.ToLowerCase();
|
||||
}
|
||||
mEditor->InsertText(key);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* these includes are for debug only. this module should never instantiate it's own transactions */
|
||||
#include "SplitElementTxn.h"
|
||||
#include "TransactionFactory.h"
|
||||
static NS_DEFINE_IID(kSplitElementTxnIID, SPLIT_ELEMENT_TXN_IID);
|
||||
nsresult
|
||||
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
|
||||
{
|
||||
aProcessed=PR_FALSE;
|
||||
PRUint32 keyCode;
|
||||
PRBool isShift;
|
||||
PRBool ctrlKey;
|
||||
|
||||
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
|
||||
)
|
||||
{
|
||||
// XXX: please please please get these mappings from an external source!
|
||||
switch (keyCode)
|
||||
{
|
||||
// XXX: hard-coded undo
|
||||
case nsIDOMEvent::VK_Z:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if ((nsITextEditor *)nsnull!=mEditor)
|
||||
mEditor->Undo(1);
|
||||
}
|
||||
break;
|
||||
|
||||
// XXX: hard-coded redo
|
||||
case nsIDOMEvent::VK_Y:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if ((nsITextEditor *)nsnull!=mEditor)
|
||||
mEditor->Redo(1);
|
||||
}
|
||||
break;
|
||||
|
||||
// hard-coded split node test: works on first <P> in the document
|
||||
case nsIDOMEvent::VK_S:
|
||||
/*
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
nsAutoString pTag("P");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
nsresult result;
|
||||
SplitElementTxn *txn;
|
||||
if (PR_FALSE==isShift) // split the element so there are 0 children in the first half
|
||||
{
|
||||
result = TransactionFactory::GetNewTransaction(kSplitElementTxnIID, (EditTxn **)&txn);
|
||||
if (txn)
|
||||
txn->Init(mEditor, currentNode, -1);
|
||||
}
|
||||
else // split the element so there are 2 children in the first half
|
||||
{
|
||||
result = TransactionFactory::GetNewTransaction(kSplitElementTxnIID, (EditTxn **)&txn);
|
||||
if (txn)
|
||||
txn->Init(mEditor, currentNode, 1);
|
||||
}
|
||||
if (txn)
|
||||
mEditor->Do(txn);
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
|
||||
|
||||
//XXX: test for change and remove attribute, hard-coded to be width on first table in doc
|
||||
case nsIDOMEvent::VK_TAB:
|
||||
{
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
/*
|
||||
nsAutoString attribute("width");
|
||||
nsAutoString value("400");
|
||||
|
||||
nsAutoString tableTag("TABLE");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, tableTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
nsresult result;
|
||||
if (PR_TRUE==ctrlKey) // remove the attribute
|
||||
result = mEditor->RemoveAttribute(element, attribute);
|
||||
else // change the attribute
|
||||
result = mEditor->SetAttribute(element, attribute, value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_INSERT:
|
||||
{
|
||||
nsresult result;
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
/*
|
||||
nsAutoString attribute("src");
|
||||
nsAutoString value("resource:/res/samples/raptor.jpg");
|
||||
|
||||
nsAutoString imgTag("HR");
|
||||
nsAutoString bodyTag("BODY");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
result = mEditor->GetFirstNodeOfType(nsnull, bodyTag, getter_AddRefs(currentNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
PRInt32 position;
|
||||
if (PR_TRUE==ctrlKey)
|
||||
position=CreateElementTxn::eAppend;
|
||||
else
|
||||
position=0;
|
||||
result = mEditor->CreateNode(imgTag, currentNode, position);
|
||||
}
|
||||
mEditor->InsertNode(nsnull, nsnull, 0);
|
||||
*/
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* nsTextEditorMouseListener implementation
|
||||
*/
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditorMouseListener)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextEditorMouseListener)
|
||||
|
||||
|
||||
nsTextEditorMouseListener::nsTextEditorMouseListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsTextEditorMouseListener::~nsTextEditorMouseListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::ProcessEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> target;
|
||||
if (NS_OK == aMouseEvent->GetTarget(getter_AddRefs(target))) {
|
||||
// nsSetCurrentNode(aTarget);
|
||||
}
|
||||
//Should not be error. Need a new way to do return values
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Factory functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
nsITextEditor *aEditor)
|
||||
{
|
||||
nsTextEditorKeyListener* it = new nsTextEditorKeyListener();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
it->SetEditor(aEditor);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
nsITextEditor *aEditor)
|
||||
{
|
||||
nsTextEditorMouseListener* it = new nsTextEditorMouseListener();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
it->SetEditor(aEditor);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* -*- 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 "nsIDOMEvent.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsCOMPtr.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(nsITextEditor *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 ProcessEvent(nsIDOMEvent* aEvent);
|
||||
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
|
||||
/*END interfaces from nsIDOMKeyListener*/
|
||||
|
||||
protected:
|
||||
virtual nsresult GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar);
|
||||
virtual nsresult ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsITextEditor> mEditor;
|
||||
};
|
||||
|
||||
|
||||
/** editor Implementation of the MouseListener 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(nsITextEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of mouseevent handler interface*/
|
||||
virtual nsresult ProcessEvent(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:
|
||||
nsCOMPtr<nsITextEditor> mEditor;
|
||||
|
||||
};
|
||||
|
||||
/** factory for the editor key listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
|
||||
|
||||
/** factory for the editor mouse listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
|
||||
|
||||
#endif //editorInterfaces_h__
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
/* -*- 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 "nsRepository.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kITextEditorIID, NS_ITEXTEDITOR_IID);
|
||||
static NS_DEFINE_IID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
static NS_DEFINE_IID(kITextEditFactoryIID, NS_ITEXTEDITORFACTORY_IID);
|
||||
|
||||
|
||||
nsresult
|
||||
GetTextEditFactory(nsIFactory **aFactory, const nsCID & aClass)
|
||||
{
|
||||
static nsCOMPtr<nsIFactory> g_pNSIFactory;
|
||||
PR_EnterMonitor(getEditorMonitor());
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
if (!g_pNSIFactory)
|
||||
{
|
||||
nsTextEditFactory *factory = new nsTextEditFactory(aClass);
|
||||
g_pNSIFactory = factory;
|
||||
if (factory)
|
||||
result = NS_OK;
|
||||
}
|
||||
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
|
||||
PR_ExitMonitor(getEditorMonitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports
|
||||
|
||||
NS_METHOD
|
||||
nsTextEditFactory::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(nsTextEditFactory)
|
||||
NS_IMPL_RELEASE(nsTextEditFactory)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsIFactory:
|
||||
|
||||
NS_METHOD
|
||||
nsTextEditFactory::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(kTextEditorCID))
|
||||
obj = (nsISupports *)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_METHOD
|
||||
nsTextEditFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsTextEditFactory:
|
||||
|
||||
nsTextEditFactory::nsTextEditFactory(const nsCID &aClass)
|
||||
:mCID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsTextEditFactory::~nsTextEditFactory()
|
||||
{
|
||||
//nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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 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);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsTextEditFactory:
|
||||
|
||||
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___
|
|
@ -0,0 +1,391 @@
|
|||
/* -*- 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 "nsTextEditor.h"
|
||||
#include "nsEditorEventListeners.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsEditorCID.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
|
||||
static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
|
||||
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kITextEditorIID, NS_ITEXTEDITOR_IID);
|
||||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
|
||||
|
||||
|
||||
nsTextEditor::nsTextEditor()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsTextEditor::~nsTextEditor()
|
||||
{
|
||||
//the autopointers will clear themselves up.
|
||||
//but we need to also remove the listeners or we have a leak
|
||||
if (mEditor)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mEditor->GetDocument(getter_AddRefs(doc));
|
||||
if (doc)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventReceiver> erP;
|
||||
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
||||
if (NS_SUCCEEDED(result) && erP)
|
||||
{
|
||||
if (mKeyListenerP) {
|
||||
erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
||||
}
|
||||
if (mMouseListenerP) {
|
||||
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
||||
}
|
||||
}
|
||||
else
|
||||
NS_NOTREACHED("~nsTextEditor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc,
|
||||
nsIPresShell *aPresShell,
|
||||
nsIEditorCallback *aCallback)
|
||||
{
|
||||
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
|
||||
nsresult result=NS_ERROR_NULL_POINTER;
|
||||
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
||||
{
|
||||
// get the editor
|
||||
nsIEditor *editor = nsnull;
|
||||
result = nsRepository::CreateInstance(kEditorCID, nsnull,
|
||||
kIEditorIID, (void **)&editor);
|
||||
if (NS_FAILED(result) || !editor) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mEditor = editor; // CreateInstance did our addRef
|
||||
|
||||
mEditor->Init(aDoc, aPresShell);
|
||||
mEditor->EnableUndo(PR_TRUE);
|
||||
|
||||
result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this);
|
||||
if (NS_OK != result) {
|
||||
mKeyListenerP = 0; // drop the key listener if we couldn't get a mouse listener
|
||||
return result;
|
||||
}
|
||||
nsCOMPtr<nsIDOMEventReceiver> erP;
|
||||
result = aDoc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
||||
if (NS_OK != result)
|
||||
{
|
||||
mKeyListenerP = 0;
|
||||
mMouseListenerP = 0; //dont need these if we cant register them
|
||||
return result;
|
||||
}
|
||||
erP->AddEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
||||
//erP->AddEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
||||
|
||||
result = NS_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::SetTextProperties(nsVoidArray *aPropList)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::GetTextProperties(nsVoidArray *aPropList)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::RemoveTextProperties(nsVoidArray *aPropList)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->DeleteSelection(aDir);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::InsertText(const nsString& aStringToInsert)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->InsertText(aStringToInsert);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::InsertBreak(PRBool aCtrlKey)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::EnableUndo(PRBool aEnable)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->EnableUndo(aEnable);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::Undo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->Undo(aCount);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::Redo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->Redo(aCount);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::BeginTransaction()
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->BeginTransaction();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::EndTransaction()
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = mEditor->EndTransaction();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::ScrollUp(nsIAtom *aIncrement)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::ScrollDown(nsIAtom *aIncrement)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::ScrollIntoView(PRBool aScrollToBegin)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::Insert(nsIInputStream *aInputStream)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::OutputText(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsTextEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||
if (mEditor)
|
||||
{
|
||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditor)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextEditor)
|
||||
|
||||
nsresult
|
||||
nsTextEditor::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(kITextEditorIID)) {
|
||||
*aInstancePtr = (void*)(nsITextEditor*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
|
@ -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 nsTextEditor_h__
|
||||
#define nsTextEditor_h__
|
||||
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
|
||||
/**
|
||||
* 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 nsITextEditor
|
||||
{
|
||||
public:
|
||||
// see nsITextEditor for documentation
|
||||
|
||||
//Interfaces for addref and release and queryinterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//Initialization
|
||||
nsTextEditor();
|
||||
virtual nsresult InitTextEditor(nsIDOMDocument *aDoc,
|
||||
nsIPresShell *aPresShell,
|
||||
nsIEditorCallback *aCallback=nsnull);
|
||||
virtual ~nsTextEditor();
|
||||
|
||||
// Editing Operations
|
||||
virtual nsresult SetTextProperties(nsVoidArray *aPropList);
|
||||
virtual nsresult GetTextProperties(nsVoidArray *aPropList);
|
||||
virtual nsresult RemoveTextProperties(nsVoidArray *aPropList);
|
||||
virtual nsresult DeleteSelection(nsIEditor::Direction aDir);
|
||||
virtual nsresult InsertText(const nsString& aStringToInsert);
|
||||
virtual nsresult InsertBreak(PRBool aCtrlKey);
|
||||
|
||||
// Transaction control
|
||||
virtual nsresult EnableUndo(PRBool aEnable);
|
||||
virtual nsresult Undo(PRUint32 aCount);
|
||||
virtual nsresult CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
virtual nsresult Redo(PRUint32 aCount);
|
||||
virtual nsresult CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
virtual nsresult BeginTransaction();
|
||||
virtual nsresult EndTransaction();
|
||||
|
||||
// Selection and navigation -- exposed here for convenience
|
||||
virtual nsresult MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
|
||||
virtual nsresult ScrollUp(nsIAtom *aIncrement);
|
||||
virtual nsresult ScrollDown(nsIAtom *aIncrement);
|
||||
virtual nsresult ScrollIntoView(PRBool aScrollToBegin);
|
||||
|
||||
// Input/Output
|
||||
virtual nsresult Insert(nsIInputStream *aInputStream);
|
||||
virtual nsresult OutputText(nsIOutputStream *aOutputStream);
|
||||
virtual nsresult OutputHTML(nsIOutputStream *aOutputStream);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIEditor> mEditor;
|
||||
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||
|
||||
};
|
||||
|
||||
#endif //nsTextEditor_h__
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "ChangeAttributeTxn.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "editor.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
ChangeAttributeTxn::ChangeAttributeTxn()
|
||||
: EditTxn()
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "InsertTextTxn.h"
|
||||
#include "editor.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIPresShell.h"
|
||||
|
@ -49,11 +49,8 @@ nsresult InsertTextTxn::Do(void)
|
|||
// advance caret: This requires the presentation shell to get the selection.
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
res = mPresShell->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
// We know mOffset+Length should be there
|
||||
// because we just added that many characters.
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -65,7 +62,11 @@ nsresult InsertTextTxn::Undo(void)
|
|||
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(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,264 @@
|
|||
/* -*- 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 "prmon.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIContextLoader.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "TransactionFactory.h"
|
||||
#include "nsRepository.h"
|
||||
//#include "nsISelection.h"
|
||||
|
||||
class nsIDOMCharacterData;
|
||||
class nsIDOMRange;
|
||||
class nsIPresShell;
|
||||
class nsIViewManager;
|
||||
class ChangeAttributeTxn;
|
||||
class CreateElementTxn;
|
||||
class DeleteElementTxn;
|
||||
class InsertTextTxn;
|
||||
class DeleteTextTxn;
|
||||
class SplitElementTxn;
|
||||
class JoinElementTxn;
|
||||
class EditAggregateTxn;
|
||||
class nsVoidArray;
|
||||
|
||||
//This is the monitor for the editor.
|
||||
PRMonitor *getEditorMonitor();
|
||||
|
||||
/*
|
||||
struct Properties
|
||||
{
|
||||
Properties (nsIAtom *aPropName, nsIAtom *aValue, PRBool aAppliesToAll);
|
||||
~Properties();
|
||||
|
||||
nsIAtom *mPropName;
|
||||
nsIAtom *mValue;
|
||||
PRBool mAppliesToAll;
|
||||
};
|
||||
|
||||
inline Property::Property(nsIAtom *aPropName, nsIAtom *aValue, PRBool aAppliesToAll)
|
||||
{
|
||||
mPropName = aPropName;
|
||||
mPropValue = aPropValue;
|
||||
mAppliesToAll = aAppliesToAll;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
/** 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
|
||||
{
|
||||
private:
|
||||
nsIPresShell *mPresShell;
|
||||
nsIViewManager *mViewManager;
|
||||
PRUint32 mUpdateCount;
|
||||
nsCOMPtr<nsIDOMDocument> mDoc;
|
||||
nsCOMPtr<nsITransactionManager> mTxnMgr;
|
||||
|
||||
|
||||
friend PRBool NSCanUnload(void);
|
||||
static PRInt32 gInstanceCount;
|
||||
|
||||
public:
|
||||
/** 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();
|
||||
|
||||
/*BEGIN nsIEdieditor for more details*/
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell);
|
||||
|
||||
virtual nsresult GetDocument(nsIDOMDocument **aDoc);
|
||||
|
||||
virtual nsresult SetProperties(nsVoidArray *aPropList);
|
||||
|
||||
virtual nsresult GetProperties(nsVoidArray *aPropList);
|
||||
|
||||
virtual nsresult SetAttribute(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue);
|
||||
|
||||
virtual nsresult GetAttributeValue(nsIDOMElement * aElement,
|
||||
const nsString& aAttribute,
|
||||
nsString& aResultValue,
|
||||
PRBool& aResultIsSet);
|
||||
|
||||
virtual nsresult RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute);
|
||||
|
||||
virtual nsresult CreateNode(const nsString& aTag,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition);
|
||||
|
||||
virtual nsresult InsertNode(nsIDOMNode * aNode,
|
||||
nsIDOMNode * aParent,
|
||||
PRInt32 aPosition);
|
||||
virtual nsresult InsertText(const nsString& aStringToInsert);
|
||||
|
||||
virtual nsresult DeleteNode(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aChild);
|
||||
|
||||
virtual nsresult DeleteSelection(nsIEditor::Direction aDir);
|
||||
|
||||
virtual nsresult SplitNode(nsIDOMNode * aExistingRightNode,
|
||||
PRInt32 aOffset,
|
||||
nsIDOMNode * aNewLeftNode,
|
||||
nsIDOMNode * aParent);
|
||||
|
||||
virtual nsresult JoinNodes(nsIDOMNode * aNodeToKeep,
|
||||
nsIDOMNode * aNodeToJoin,
|
||||
nsIDOMNode * aParent,
|
||||
PRBool aNodeToKeepIsFirst);
|
||||
|
||||
virtual nsresult InsertBreak(PRBool aCtrlKey);
|
||||
|
||||
virtual nsresult EnableUndo(PRBool aEnable);
|
||||
|
||||
virtual nsresult Do(nsITransaction *aTxn);
|
||||
|
||||
virtual nsresult Undo(PRUint32 aCount);
|
||||
|
||||
virtual nsresult CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
|
||||
|
||||
virtual nsresult Redo(PRUint32 aCount);
|
||||
|
||||
virtual nsresult CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
|
||||
|
||||
virtual nsresult BeginTransaction();
|
||||
|
||||
virtual nsresult EndTransaction();
|
||||
|
||||
/*END nsIEditor interfaces*/
|
||||
|
||||
|
||||
/*BEGIN public methods unique to nsEditor. These will get moved to an interface
|
||||
if they survive.
|
||||
*/
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
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 nsIDOMNode *aStartNode is the node to start looking from
|
||||
* @param nsIAtom *aTag is the type of node we are searching for
|
||||
* @param nsIDOMNode **aResult is the node we found, or nsnull if there is none
|
||||
*/
|
||||
nsresult GetFirstNodeOfType(nsIDOMNode *aStartNode, const nsString &aTag, nsIDOMNode **aResult);
|
||||
|
||||
/*END public methods of nsEditor*/
|
||||
|
||||
|
||||
/*BEGIN private methods used by the implementations of the above functions*/
|
||||
protected:
|
||||
virtual nsresult CreateTxnForSetAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
const nsString& aValue,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
|
||||
const nsString& aAttribute,
|
||||
ChangeAttributeTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForCreateElement(const nsString& aTag,
|
||||
nsIDOMNode *aParent,
|
||||
PRInt32 aPosition,
|
||||
CreateElementTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteElement(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aElement,
|
||||
DeleteElementTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForInsertText(const nsString & aStringToInsert,
|
||||
InsertTextTxn ** aTxn);
|
||||
|
||||
|
||||
virtual nsresult DeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLength,
|
||||
DeleteTextTxn **aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
||||
nsIEditor::Direction aDir,
|
||||
EditAggregateTxn *aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
PRUint32 aOffset,
|
||||
SplitElementTxn **aTxn);
|
||||
|
||||
virtual nsresult CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
|
||||
nsIDOMNode *aRightNode,
|
||||
JoinElementTxn **aTxn);
|
||||
|
||||
#if 0
|
||||
nsresult CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
||||
#endif
|
||||
|
||||
nsresult GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetRightmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
nsresult GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
factory method(s)
|
||||
*/
|
||||
|
||||
nsresult NS_MakeEditorLoader(nsIContextLoader **aResult);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,480 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
#include "nsEditorEventListeners.h"
|
||||
#include "nsEditor.h"
|
||||
|
||||
#include "CreateElementTxn.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
||||
|
||||
|
||||
/*
|
||||
* nsTextEditorKeyListener implementation
|
||||
*/
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditorKeyListener)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextEditorKeyListener)
|
||||
|
||||
|
||||
nsTextEditorKeyListener::nsTextEditorKeyListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsTextEditorKeyListener::~nsTextEditorKeyListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::ProcessEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar)
|
||||
{
|
||||
/* This is completely temporary to get this working while I check out Unicode conversion code. */
|
||||
#ifdef XP_MAC
|
||||
if (aChar) {
|
||||
*aChar = (char)aKeyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
#else
|
||||
if (aKeyCode >= 0x41 && aKeyCode <= 0x5A) {
|
||||
if (aIsShift) {
|
||||
*aChar = (char)aKeyCode;
|
||||
}
|
||||
else {
|
||||
*aChar = (char)(aKeyCode + 0x20);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
else if ((aKeyCode >= 0x30 && aKeyCode <= 0x39) || aKeyCode == 0x20) {
|
||||
*aChar = (char)aKeyCode;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
PRUint32 keyCode;
|
||||
PRBool isShift;
|
||||
PRBool ctrlKey;
|
||||
char character;
|
||||
|
||||
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
|
||||
) {
|
||||
PRBool keyProcessed;
|
||||
ProcessShortCutKeys(aKeyEvent, keyProcessed);
|
||||
if (PR_FALSE==keyProcessed)
|
||||
{
|
||||
switch(keyCode) {
|
||||
case nsIDOMEvent::VK_BACK:
|
||||
mEditor->DeleteSelection(nsIEditor::eRTL);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_DELETE:
|
||||
mEditor->DeleteSelection(nsIEditor::eLTR);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_RETURN:
|
||||
// Need to implement creation of either <P> or <BR> nodes.
|
||||
mEditor->InsertBreak(ctrlKey);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// XXX Replace with x-platform NS-virtkeycode transform.
|
||||
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
||||
nsAutoString key;
|
||||
key += character;
|
||||
if (!isShift) {
|
||||
key.ToLowerCase();
|
||||
}
|
||||
mEditor->InsertText(key);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* these includes are for debug only. this module should never instantiate it's own transactions */
|
||||
#include "SplitElementTxn.h"
|
||||
#include "TransactionFactory.h"
|
||||
static NS_DEFINE_IID(kSplitElementTxnIID, SPLIT_ELEMENT_TXN_IID);
|
||||
nsresult
|
||||
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
|
||||
{
|
||||
aProcessed=PR_FALSE;
|
||||
PRUint32 keyCode;
|
||||
PRBool isShift;
|
||||
PRBool ctrlKey;
|
||||
|
||||
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
|
||||
)
|
||||
{
|
||||
// XXX: please please please get these mappings from an external source!
|
||||
switch (keyCode)
|
||||
{
|
||||
// XXX: hard-coded undo
|
||||
case nsIDOMEvent::VK_Z:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if ((nsITextEditor *)nsnull!=mEditor)
|
||||
mEditor->Undo(1);
|
||||
}
|
||||
break;
|
||||
|
||||
// XXX: hard-coded redo
|
||||
case nsIDOMEvent::VK_Y:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if ((nsITextEditor *)nsnull!=mEditor)
|
||||
mEditor->Redo(1);
|
||||
}
|
||||
break;
|
||||
|
||||
// hard-coded split node test: works on first <P> in the document
|
||||
case nsIDOMEvent::VK_S:
|
||||
/*
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
nsAutoString pTag("P");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
nsresult result;
|
||||
SplitElementTxn *txn;
|
||||
if (PR_FALSE==isShift) // split the element so there are 0 children in the first half
|
||||
{
|
||||
result = TransactionFactory::GetNewTransaction(kSplitElementTxnIID, (EditTxn **)&txn);
|
||||
if (txn)
|
||||
txn->Init(mEditor, currentNode, -1);
|
||||
}
|
||||
else // split the element so there are 2 children in the first half
|
||||
{
|
||||
result = TransactionFactory::GetNewTransaction(kSplitElementTxnIID, (EditTxn **)&txn);
|
||||
if (txn)
|
||||
txn->Init(mEditor, currentNode, 1);
|
||||
}
|
||||
if (txn)
|
||||
mEditor->Do(txn);
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
|
||||
|
||||
//XXX: test for change and remove attribute, hard-coded to be width on first table in doc
|
||||
case nsIDOMEvent::VK_TAB:
|
||||
{
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
/*
|
||||
nsAutoString attribute("width");
|
||||
nsAutoString value("400");
|
||||
|
||||
nsAutoString tableTag("TABLE");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, tableTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
if (NS_SUCCEEDED(currentNode->QueryInterface(kIDOMElementIID, getter_AddRefs(element))))
|
||||
{
|
||||
nsresult result;
|
||||
if (PR_TRUE==ctrlKey) // remove the attribute
|
||||
result = mEditor->RemoveAttribute(element, attribute);
|
||||
else // change the attribute
|
||||
result = mEditor->SetAttribute(element, attribute, value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_INSERT:
|
||||
{
|
||||
nsresult result;
|
||||
//XXX: should be from a factory
|
||||
//XXX: should manage the refcount of txn
|
||||
/*
|
||||
nsAutoString attribute("src");
|
||||
nsAutoString value("resource:/res/samples/raptor.jpg");
|
||||
|
||||
nsAutoString imgTag("HR");
|
||||
nsAutoString bodyTag("BODY");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
result = mEditor->GetFirstNodeOfType(nsnull, bodyTag, getter_AddRefs(currentNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
PRInt32 position;
|
||||
if (PR_TRUE==ctrlKey)
|
||||
position=CreateElementTxn::eAppend;
|
||||
else
|
||||
position=0;
|
||||
result = mEditor->CreateNode(imgTag, currentNode, position);
|
||||
}
|
||||
mEditor->InsertNode(nsnull, nsnull, 0);
|
||||
*/
|
||||
}
|
||||
aProcessed=PR_TRUE;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* nsTextEditorMouseListener implementation
|
||||
*/
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextEditorMouseListener)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextEditorMouseListener)
|
||||
|
||||
|
||||
nsTextEditorMouseListener::nsTextEditorMouseListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsTextEditorMouseListener::~nsTextEditorMouseListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::ProcessEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> target;
|
||||
if (NS_OK == aMouseEvent->GetTarget(getter_AddRefs(target))) {
|
||||
// nsSetCurrentNode(aTarget);
|
||||
}
|
||||
//Should not be error. Need a new way to do return values
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Factory functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
nsITextEditor *aEditor)
|
||||
{
|
||||
nsTextEditorKeyListener* it = new nsTextEditorKeyListener();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
it->SetEditor(aEditor);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
nsITextEditor *aEditor)
|
||||
{
|
||||
nsTextEditorMouseListener* it = new nsTextEditorMouseListener();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
it->SetEditor(aEditor);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||
|
||||
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* -*- 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 "nsIDOMEvent.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsCOMPtr.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(nsITextEditor *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 ProcessEvent(nsIDOMEvent* aEvent);
|
||||
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
|
||||
/*END interfaces from nsIDOMKeyListener*/
|
||||
|
||||
protected:
|
||||
virtual nsresult GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar);
|
||||
virtual nsresult ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsITextEditor> mEditor;
|
||||
};
|
||||
|
||||
|
||||
/** editor Implementation of the MouseListener 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(nsITextEditor *aEditor){mEditor = aEditor;}
|
||||
|
||||
/*interfaces for addref and release and queryinterface*/
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/*BEGIN implementations of mouseevent handler interface*/
|
||||
virtual nsresult ProcessEvent(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:
|
||||
nsCOMPtr<nsITextEditor> mEditor;
|
||||
|
||||
};
|
||||
|
||||
/** factory for the editor key listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
|
||||
|
||||
/** factory for the editor mouse listener
|
||||
*/
|
||||
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
|
||||
|
||||
#endif //editorInterfaces_h__
|
||||
|
Загрузка…
Ссылка в новой задаче