Back to index

lightning-sunbird  0.9+nobinonly
nsEditingSession.h
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  *   Simon Fraser <sfraser@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsEditingSession_h__
00040 #define nsEditingSession_h__
00041 
00042 
00043 #ifndef nsWeakReference_h__
00044 #include "nsWeakReference.h"
00045 #endif
00046 
00047 #include "nsITimer.h"
00048 
00049 #ifndef __gen_nsIURIContentListener_h__
00050 #include "nsIURIContentListener.h"
00051 #endif
00052 
00053 #ifndef __gen_nsIWebProgressListener_h__
00054 #include "nsIWebProgressListener.h"
00055 #endif
00056 
00057 #ifndef __gen_nsIEditingSession_h__
00058 #include "nsIEditingSession.h"
00059 #endif
00060 
00061 #include "nsString.h"
00062 
00063 #define NS_EDITINGSESSION_CID                            \
00064 { 0xbc26ff01, 0xf2bd, 0x11d4, { 0xa7, 0x3c, 0xe5, 0xa4, 0xb5, 0xa8, 0xbd, 0xfc } }
00065 
00066 
00067 class nsIWebProgress;
00068 class nsIDocShell;
00069 class nsIEditorDocShell;
00070 class nsIChannel;
00071 class nsIEditor;
00072 class nsIControllers;
00073 
00074 class nsComposerCommandsUpdater;
00075 
00076 class nsEditingSession : public nsIEditingSession,
00077                          public nsIWebProgressListener,
00078                          public nsIURIContentListener,
00079                          public nsSupportsWeakReference
00080 {
00081 public:
00082 
00083                   nsEditingSession();
00084   virtual         ~nsEditingSession();
00085 
00086   // nsISupports
00087   NS_DECL_ISUPPORTS
00088 
00089   // nsIURIContentListener
00090   NS_DECL_NSIURICONTENTLISTENER
00091 
00092   // nsIWebProgressListener
00093   NS_DECL_NSIWEBPROGRESSLISTENER
00094   
00095   // nsIEditingSession
00096   NS_DECL_NSIEDITINGSESSION
00097 
00098 protected:
00099 
00100   nsIDocShell *   GetDocShellFromWindow(nsIDOMWindow *aWindow);
00101   nsresult        GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, 
00102                                               nsIEditorDocShell** outDocShell);
00103   
00104   nsresult        SetupEditorCommandController(const char *aControllerClassName,
00105                                                nsIDOMWindow *aWindow,
00106                                                nsISupports *aContext,
00107                                                PRUint32 *aControllerId);
00108 
00109   nsresult        SetContextOnControllerById(nsIControllers* aControllers, 
00110                                             nsISupports* aContext,
00111                                             PRUint32 aID);
00112 
00113   nsresult        PrepareForEditing(nsIDOMWindow *aWindow);
00114 
00115   static void     TimerCallback(nsITimer *aTimer, void *aClosure);
00116   nsCOMPtr<nsITimer>  mLoadBlankDocTimer;
00117   
00118   // progress load stuff
00119   nsresult        StartDocumentLoad(nsIWebProgress *aWebProgress,
00120                                     PRBool isToBeMadeEditable);
00121   nsresult        EndDocumentLoad(nsIWebProgress *aWebProgress, 
00122                                   nsIChannel* aChannel, nsresult aStatus,
00123                                   PRBool isToBeMadeEditable);
00124   nsresult        StartPageLoad(nsIChannel *aChannel);
00125   nsresult        EndPageLoad(nsIWebProgress *aWebProgress, 
00126                               nsIChannel* aChannel, nsresult aStatus);
00127   
00128   PRBool          IsProgressForTargetDocument(nsIWebProgress *aWebProgress);
00129 
00130 protected:
00131 
00132   PRPackedBool    mDoneSetup;    // have we prepared for editing yet?
00133 
00134   // Used to prevent double creation of editor because nsIWebProgressListener
00135   //  receives a STATE_STOP notification before the STATE_START 
00136   //  for our document, so we wait for the STATE_START, then STATE_STOP 
00137   //  before creating an editor
00138   PRPackedBool    mCanCreateEditor; 
00139 
00140   // True if scripts were enabled before the editor turned scripts
00141   // off, otherwise false.
00142   PRPackedBool    mScriptsEnabled;
00143 
00144   // True if plugins were enabled before the editor turned plugins
00145   // off, otherwise false.
00146   PRPackedBool    mPluginsEnabled;
00147 
00148   PRPackedBool    mProgressListenerRegistered;
00149 
00150   // The image animation mode before it was turned off.
00151   PRUint16        mImageAnimationMode;
00152 
00153   // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT
00154   // MORE THAN ONE EDITOR PER EDITING SESSION
00155   nsCOMPtr<nsISupports> mStateMaintainer;  // we hold the owning ref to this
00156   
00157   nsWeakPtr       mWindowToBeEdited;
00158 
00159   // Save the editor type so we can create the editor after loading uri
00160   nsCString       mEditorType; 
00161   PRUint32        mEditorFlags;
00162   PRUint32        mEditorStatus;
00163   PRUint32        mBaseCommandControllerId;
00164   PRUint32        mDocStateControllerId;
00165   PRUint32        mHTMLCommandControllerId;
00166 };
00167 
00168 
00169 
00170 #endif // nsEditingSession_h__