no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / editor / composer / nsEditingSession.h
blobee2c035586142d65fa26aa66ad5d101bf4e114f5
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/. */
6 #ifndef nsEditingSession_h__
7 #define nsEditingSession_h__
9 #include "nsCOMPtr.h" // for nsCOMPtr
10 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS
11 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
12 #include "nsWeakReference.h" // for nsSupportsWeakReference, etc
13 #include "nscore.h" // for nsresult
15 #ifndef __gen_nsIWebProgressListener_h__
16 # include "nsIWebProgressListener.h"
17 #endif
19 #ifndef __gen_nsIEditingSession_h__
20 # include "nsIEditingSession.h" // for NS_DECL_NSIEDITINGSESSION, etc
21 #endif
23 #include "nsString.h" // for nsCString
25 class mozIDOMWindowProxy;
26 class nsBaseCommandController;
27 class nsIDOMWindow;
28 class nsISupports;
29 class nsITimer;
30 class nsIChannel;
31 class nsIControllers;
32 class nsIDocShell;
33 class nsIWebProgress;
34 class nsIPIDOMWindowOuter;
35 class nsIPIDOMWindowInner;
37 namespace mozilla {
38 class ComposerCommandsUpdater;
39 class HTMLEditor;
40 } // namespace mozilla
42 class nsEditingSession final : public nsIEditingSession,
43 public nsIWebProgressListener,
44 public nsSupportsWeakReference {
45 public:
46 nsEditingSession();
48 // nsISupports
49 NS_DECL_ISUPPORTS
51 // nsIWebProgressListener
52 NS_DECL_NSIWEBPROGRESSLISTENER
54 // nsIEditingSession
55 NS_DECL_NSIEDITINGSESSION
57 /**
58 * Removes all the editor's controllers/listeners etc and makes the window
59 * uneditable.
61 nsresult DetachFromWindow(nsPIDOMWindowOuter* aWindow);
63 /**
64 * Undos DetachFromWindow(), reattaches this editing session/editor
65 * to the window.
67 nsresult ReattachToWindow(nsPIDOMWindowOuter* aWindow);
69 protected:
70 virtual ~nsEditingSession();
72 typedef already_AddRefed<nsBaseCommandController> (*ControllerCreatorFn)();
74 nsresult SetupEditorCommandController(
75 ControllerCreatorFn aControllerCreatorFn, mozIDOMWindowProxy* aWindow,
76 nsISupports* aContext, uint32_t* aControllerId);
78 nsresult SetContextOnControllerById(nsIControllers* aControllers,
79 nsISupports* aContext, uint32_t aID);
81 /**
82 * Set the editor on the controller(s) for this window
84 nsresult SetEditorOnControllers(nsPIDOMWindowOuter& aWindow,
85 mozilla::HTMLEditor* aEditor);
87 /**
88 * Setup editor and related support objects
90 MOZ_CAN_RUN_SCRIPT nsresult SetupEditorOnWindow(nsPIDOMWindowOuter& aWindow);
92 nsresult PrepareForEditing(nsPIDOMWindowOuter* aWindow);
94 static void TimerCallback(nsITimer* aTimer, void* aClosure);
95 nsCOMPtr<nsITimer> mLoadBlankDocTimer;
97 // progress load stuff
98 nsresult StartDocumentLoad(nsIWebProgress* aWebProgress,
99 bool isToBeMadeEditable);
100 MOZ_CAN_RUN_SCRIPT_BOUNDARY
101 nsresult EndDocumentLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel,
102 nsresult aStatus, bool isToBeMadeEditable);
103 nsresult StartPageLoad(nsIChannel* aChannel);
104 nsresult EndPageLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel,
105 nsresult aStatus);
107 bool IsProgressForTargetDocument(nsIWebProgress* aWebProgress);
109 void RemoveEditorControllers(nsPIDOMWindowOuter* aWindow);
110 void RemoveWebProgressListener(nsPIDOMWindowOuter* aWindow);
111 void RestoreAnimationMode(nsPIDOMWindowOuter* aWindow);
112 void RemoveListenersAndControllers(nsPIDOMWindowOuter* aWindow,
113 mozilla::HTMLEditor* aHTMLEditor);
116 * Disable scripts in aDocShell.
118 nsresult DisableJS(nsPIDOMWindowInner* aWindow);
121 * Restore JS (enable/disable) according to the state it
122 * was before the last call to DisableJS.
124 nsresult RestoreJS(nsPIDOMWindowInner* aWindow);
126 protected:
127 bool mDoneSetup; // have we prepared for editing yet?
129 // Used to prevent double creation of editor because nsIWebProgressListener
130 // receives a STATE_STOP notification before the STATE_START
131 // for our document, so we wait for the STATE_START, then STATE_STOP
132 // before creating an editor
133 bool mCanCreateEditor;
135 bool mInteractive;
136 bool mMakeWholeDocumentEditable;
138 bool mDisabledJS;
140 // True if scripts were enabled before the editor turned scripts
141 // off, otherwise false.
142 bool mScriptsEnabled;
144 bool mProgressListenerRegistered;
146 // The image animation mode before it was turned off.
147 uint16_t mImageAnimationMode;
149 // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT
150 // MORE THAN ONE EDITOR PER EDITING SESSION
151 RefPtr<mozilla::ComposerCommandsUpdater> mComposerCommandsUpdater;
153 // Save the editor type so we can create the editor after loading uri
154 nsCString mEditorType;
155 uint32_t mEditorFlags;
156 uint32_t mEditorStatus;
157 uint32_t mBaseCommandControllerId;
158 uint32_t mDocStateControllerId;
159 uint32_t mHTMLCommandControllerId;
161 // Make sure the docshell we use is safe
162 nsWeakPtr mDocShell;
164 // See if we can reuse an existing editor
165 nsWeakPtr mExistingEditor;
168 #endif // nsEditingSession_h__