|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsEditingSession_h__ |
|
7 #define nsEditingSession_h__ |
|
8 |
|
9 |
|
10 #ifndef nsWeakReference_h__ |
|
11 #include "nsWeakReference.h" // for nsSupportsWeakReference, etc |
|
12 #endif |
|
13 |
|
14 #include "nsAutoPtr.h" // for nsRefPtr |
|
15 #include "nsCOMPtr.h" // for nsCOMPtr |
|
16 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS |
|
17 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr |
|
18 #include "nsWeakReference.h" // for nsSupportsWeakReference, etc |
|
19 #include "nscore.h" // for nsresult |
|
20 |
|
21 #ifndef __gen_nsIWebProgressListener_h__ |
|
22 #include "nsIWebProgressListener.h" |
|
23 #endif |
|
24 |
|
25 #ifndef __gen_nsIEditingSession_h__ |
|
26 #include "nsIEditingSession.h" // for NS_DECL_NSIEDITINGSESSION, etc |
|
27 #endif |
|
28 |
|
29 #include "nsString.h" // for nsCString |
|
30 |
|
31 class nsIDOMWindow; |
|
32 class nsISupports; |
|
33 class nsITimer; |
|
34 |
|
35 #define NS_EDITINGSESSION_CID \ |
|
36 { 0xbc26ff01, 0xf2bd, 0x11d4, { 0xa7, 0x3c, 0xe5, 0xa4, 0xb5, 0xa8, 0xbd, 0xfc } } |
|
37 |
|
38 |
|
39 class nsComposerCommandsUpdater; |
|
40 class nsIChannel; |
|
41 class nsIControllers; |
|
42 class nsIDocShell; |
|
43 class nsIEditor; |
|
44 class nsIWebProgress; |
|
45 |
|
46 class nsEditingSession : public nsIEditingSession, |
|
47 public nsIWebProgressListener, |
|
48 public nsSupportsWeakReference |
|
49 { |
|
50 public: |
|
51 |
|
52 nsEditingSession(); |
|
53 virtual ~nsEditingSession(); |
|
54 |
|
55 // nsISupports |
|
56 NS_DECL_ISUPPORTS |
|
57 |
|
58 // nsIWebProgressListener |
|
59 NS_DECL_NSIWEBPROGRESSLISTENER |
|
60 |
|
61 // nsIEditingSession |
|
62 NS_DECL_NSIEDITINGSESSION |
|
63 |
|
64 protected: |
|
65 |
|
66 nsIDocShell * GetDocShellFromWindow(nsIDOMWindow *aWindow); |
|
67 |
|
68 nsresult SetupEditorCommandController(const char *aControllerClassName, |
|
69 nsIDOMWindow *aWindow, |
|
70 nsISupports *aContext, |
|
71 uint32_t *aControllerId); |
|
72 |
|
73 nsresult SetContextOnControllerById(nsIControllers* aControllers, |
|
74 nsISupports* aContext, |
|
75 uint32_t aID); |
|
76 |
|
77 nsresult PrepareForEditing(nsIDOMWindow *aWindow); |
|
78 |
|
79 static void TimerCallback(nsITimer *aTimer, void *aClosure); |
|
80 nsCOMPtr<nsITimer> mLoadBlankDocTimer; |
|
81 |
|
82 // progress load stuff |
|
83 nsresult StartDocumentLoad(nsIWebProgress *aWebProgress, |
|
84 bool isToBeMadeEditable); |
|
85 nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, |
|
86 nsIChannel* aChannel, nsresult aStatus, |
|
87 bool isToBeMadeEditable); |
|
88 nsresult StartPageLoad(nsIChannel *aChannel); |
|
89 nsresult EndPageLoad(nsIWebProgress *aWebProgress, |
|
90 nsIChannel* aChannel, nsresult aStatus); |
|
91 |
|
92 bool IsProgressForTargetDocument(nsIWebProgress *aWebProgress); |
|
93 |
|
94 void RemoveEditorControllers(nsIDOMWindow *aWindow); |
|
95 void RemoveWebProgressListener(nsIDOMWindow *aWindow); |
|
96 void RestoreAnimationMode(nsIDOMWindow *aWindow); |
|
97 void RemoveListenersAndControllers(nsIDOMWindow *aWindow, |
|
98 nsIEditor *aEditor); |
|
99 |
|
100 protected: |
|
101 |
|
102 bool mDoneSetup; // have we prepared for editing yet? |
|
103 |
|
104 // Used to prevent double creation of editor because nsIWebProgressListener |
|
105 // receives a STATE_STOP notification before the STATE_START |
|
106 // for our document, so we wait for the STATE_START, then STATE_STOP |
|
107 // before creating an editor |
|
108 bool mCanCreateEditor; |
|
109 |
|
110 bool mInteractive; |
|
111 bool mMakeWholeDocumentEditable; |
|
112 |
|
113 bool mDisabledJSAndPlugins; |
|
114 |
|
115 // True if scripts were enabled before the editor turned scripts |
|
116 // off, otherwise false. |
|
117 bool mScriptsEnabled; |
|
118 |
|
119 // True if plugins were enabled before the editor turned plugins |
|
120 // off, otherwise false. |
|
121 bool mPluginsEnabled; |
|
122 |
|
123 bool mProgressListenerRegistered; |
|
124 |
|
125 // The image animation mode before it was turned off. |
|
126 uint16_t mImageAnimationMode; |
|
127 |
|
128 // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT |
|
129 // MORE THAN ONE EDITOR PER EDITING SESSION |
|
130 nsRefPtr<nsComposerCommandsUpdater> mStateMaintainer; |
|
131 |
|
132 // Save the editor type so we can create the editor after loading uri |
|
133 nsCString mEditorType; |
|
134 uint32_t mEditorFlags; |
|
135 uint32_t mEditorStatus; |
|
136 uint32_t mBaseCommandControllerId; |
|
137 uint32_t mDocStateControllerId; |
|
138 uint32_t mHTMLCommandControllerId; |
|
139 |
|
140 // Make sure the docshell we use is safe |
|
141 nsWeakPtr mDocShell; |
|
142 |
|
143 // See if we can reuse an existing editor |
|
144 nsWeakPtr mExistingEditor; |
|
145 }; |
|
146 |
|
147 |
|
148 |
|
149 #endif // nsEditingSession_h__ |