Back to index

lightning-sunbird  0.9+nobinonly
nsTSDNotifier.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsString.h"
00038 #include "nsIEditActionListener.h"
00039 #include "nsTSDNotifier.h"
00040 #include "nsTextServicesDocument.h"
00041 
00042 
00043 nsTSDNotifier::nsTSDNotifier(nsTextServicesDocument *aDoc) : mDoc(aDoc)
00044 {
00045 }
00046 
00047 nsTSDNotifier::~nsTSDNotifier()
00048 {
00049   mDoc = 0;
00050 }
00051 
00052 #define DEBUG_TSD_NOTIFIER_REFCNT 1
00053 
00054 #ifdef DEBUG_TSD_NOTIFIER_REFCNT
00055 
00056 nsrefcnt nsTSDNotifier::AddRef(void)
00057 {
00058   return ++mRefCnt;
00059 }
00060 
00061 nsrefcnt nsTSDNotifier::Release(void)
00062 {
00063   NS_PRECONDITION(0 != mRefCnt, "dup release");
00064   if (--mRefCnt == 0) {
00065     NS_DELETEXPCOM(this);
00066     return 0;
00067   }
00068   return mRefCnt;
00069 }
00070 
00071 #else
00072 
00073 NS_IMPL_ADDREF(nsTSDNotifier)
00074 NS_IMPL_RELEASE(nsTSDNotifier)
00075 
00076 #endif
00077 
00078 NS_IMPL_QUERY_INTERFACE1(nsTSDNotifier, nsIEditActionListener)
00079 
00080 NS_IMETHODIMP
00081 nsTSDNotifier::WillInsertNode(nsIDOMNode *aNode,
00082                               nsIDOMNode *aParent,
00083                               PRInt32     aPosition)
00084 {
00085   return NS_OK;
00086 }
00087 
00088 NS_IMETHODIMP
00089 nsTSDNotifier::DidInsertNode(nsIDOMNode *aNode,
00090                              nsIDOMNode *aParent,
00091                              PRInt32     aPosition,
00092                              nsresult    aResult)
00093 {
00094   if (NS_FAILED(aResult))
00095     return NS_OK;
00096 
00097   if (!mDoc)
00098     return NS_ERROR_FAILURE;
00099 
00100   return mDoc->InsertNode(aNode, aParent, aPosition);
00101 }
00102 
00103 NS_IMETHODIMP
00104 nsTSDNotifier::WillDeleteNode(nsIDOMNode *aChild)
00105 {
00106   return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP
00110 nsTSDNotifier::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
00111 {
00112   if (NS_FAILED(aResult))
00113     return NS_OK;
00114 
00115   if (!mDoc)
00116     return NS_ERROR_FAILURE;
00117 
00118   return mDoc->DeleteNode(aChild);
00119 }
00120 
00121 NS_IMETHODIMP
00122 nsTSDNotifier::WillSplitNode(nsIDOMNode *aExistingRightNode,
00123                              PRInt32     aOffset)
00124 {
00125   return NS_OK;
00126 }
00127 
00128 NS_IMETHODIMP
00129 nsTSDNotifier::DidSplitNode(nsIDOMNode *aExistingRightNode,
00130                             PRInt32     aOffset,
00131                             nsIDOMNode *aNewLeftNode,
00132                             nsresult    aResult)
00133 {
00134   if (NS_FAILED(aResult))
00135     return NS_OK;
00136 
00137   if (!mDoc)
00138     return NS_ERROR_FAILURE;
00139 
00140   return mDoc->SplitNode(aExistingRightNode, aOffset, aNewLeftNode);
00141 }
00142 
00143 NS_IMETHODIMP
00144 nsTSDNotifier::WillJoinNodes(nsIDOMNode  *aLeftNode,
00145                              nsIDOMNode  *aRightNode,
00146                              nsIDOMNode  *aParent)
00147 {
00148   return NS_OK;
00149 }
00150 
00151 NS_IMETHODIMP
00152 nsTSDNotifier::DidJoinNodes(nsIDOMNode  *aLeftNode,
00153                             nsIDOMNode  *aRightNode,
00154                             nsIDOMNode  *aParent,
00155                             nsresult     aResult)
00156 {
00157   if (NS_FAILED(aResult))
00158     return NS_OK;
00159 
00160   if (!mDoc)
00161     return NS_ERROR_FAILURE;
00162 
00163   return mDoc->JoinNodes(aLeftNode, aRightNode, aParent);
00164 }
00165 
00166 // -------------------------------
00167 // stubs for unused listen methods
00168 // -------------------------------
00169 
00170 NS_IMETHODIMP
00171 nsTSDNotifier::WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, PRInt32 aPosition)
00172 {
00173   return NS_OK;
00174 }
00175 
00176 NS_IMETHODIMP
00177 nsTSDNotifier::DidCreateNode(const nsAString& aTag, nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aPosition, nsresult aResult)
00178 {
00179   return NS_OK;
00180 }
00181 
00182 NS_IMETHODIMP
00183 nsTSDNotifier::WillInsertText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, const nsAString &aString)
00184 {
00185   return NS_OK;
00186 }
00187 
00188 NS_IMETHODIMP
00189 nsTSDNotifier::DidInsertText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, const nsAString &aString, nsresult aResult)
00190 {
00191   return NS_OK;
00192 }
00193 
00194 NS_IMETHODIMP
00195 nsTSDNotifier::WillDeleteText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRInt32 aLength)
00196 {
00197   return NS_OK;
00198 }
00199 
00200 NS_IMETHODIMP
00201 nsTSDNotifier::DidDeleteText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRInt32 aLength, nsresult aResult)
00202 {
00203   return NS_OK;
00204 }
00205 
00206 NS_IMETHODIMP
00207 nsTSDNotifier::WillDeleteSelection(nsISelection *aSelection)
00208 {
00209   return NS_OK;
00210 }
00211 
00212 NS_IMETHODIMP
00213 nsTSDNotifier::DidDeleteSelection(nsISelection *aSelection)
00214 {
00215   return NS_OK;
00216 }
00217 
00218 
00219