Bug 448909 - Need more controls WHATWG Video tag (followup patch). r=mconnor
[wine-gecko.git] / editor / composer / src / nsComposerRegistration.cpp
blob3b5c2b311e9458b41ea34662786d46e6cd68e945
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Michael Judge <mjudge@netscape.com>
24 * Charles Manske <cmanske@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsIGenericFactory.h"
42 #include "nsEditingSession.h" // for the CID
43 #include "nsComposerController.h" // for the CID
44 #include "nsEditorSpellCheck.h" // for the CID
45 #include "nsComposeTxtSrvFilter.h"
46 #include "nsIController.h"
47 #include "nsIControllerContext.h"
48 #include "nsIControllerCommandTable.h"
50 #include "nsServiceManagerUtils.h"
52 #define NS_HTMLEDITOR_COMMANDTABLE_CID \
53 { 0x13e50d8d, 0x9cee, 0x4ad1, { 0xa3, 0xa2, 0x4a, 0x44, 0x2f, 0xdf, 0x7d, 0xfa } }
55 #define NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID \
56 { 0xa33982d3, 0x1adf, 0x4162, { 0x99, 0x41, 0xf7, 0x34, 0xbc, 0x45, 0xe4, 0xed } }
59 static NS_DEFINE_CID(kHTMLEditorCommandTableCID, NS_HTMLEDITOR_COMMANDTABLE_CID);
60 static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
63 ////////////////////////////////////////////////////////////////////////
64 // Define the contructor function for the objects
66 // NOTE: This creates an instance of objects by using the default constructor
69 NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession)
70 NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck)
72 // There are no macros that enable us to have 2 constructors
73 // for the same object
75 // Here we are creating the same object with two different contract IDs
76 // and then initializing it different.
77 // Basically, we need to tell the filter whether it is doing mail or not
78 static NS_METHOD
79 nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID,
80 void **aResult, PRBool aIsForMail)
82 *aResult = NULL;
83 if (NULL != aOuter)
85 return NS_ERROR_NO_AGGREGATION;
87 nsComposeTxtSrvFilter * inst;
88 NS_NEWXPCOM(inst, nsComposeTxtSrvFilter);
89 if (NULL == inst)
91 return NS_ERROR_OUT_OF_MEMORY;
93 NS_ADDREF(inst);
94 inst->Init(aIsForMail);
95 nsresult rv = inst->QueryInterface(aIID, aResult);
96 NS_RELEASE(inst);
97 return rv;
100 static NS_METHOD
101 nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter,
102 REFNSIID aIID,
103 void **aResult)
105 return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_FALSE);
108 static NS_METHOD
109 nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter,
110 REFNSIID aIID,
111 void **aResult)
113 return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_TRUE);
117 // Constructor for a controller set up with a command table specified
118 // by the CID passed in. This function uses do_GetService to get the
119 // command table, so that every controller shares a single command
120 // table, for space-efficiency.
122 // The only reason to go via the service manager for the command table
123 // is that it holds onto the singleton for us, avoiding static variables here.
124 static nsresult
125 CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult)
127 nsresult rv;
128 nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
129 if (NS_FAILED(rv)) return rv;
131 nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv);
132 if (NS_FAILED(rv)) return rv;
134 // this guy is a singleton, so make it immutable
135 composerCommandTable->MakeImmutable();
137 nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
138 if (NS_FAILED(rv)) return rv;
140 rv = controllerContext->Init(composerCommandTable);
141 if (NS_FAILED(rv)) return rv;
143 *aResult = controller;
144 NS_ADDREF(*aResult);
145 return NS_OK;
149 // Here we make an instance of the controller that holds doc state commands.
150 // We set it up with a singleton command table.
151 static NS_METHOD
152 nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
153 void **aResult)
155 nsCOMPtr<nsIController> controller;
156 nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller));
157 if (NS_FAILED(rv)) return rv;
159 return controller->QueryInterface(aIID, aResult);
162 // Tere we make an instance of the controller that holds composer commands.
163 // We set it up with a singleton command table.
164 static NS_METHOD
165 nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
167 nsCOMPtr<nsIController> controller;
168 nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller));
169 if (NS_FAILED(rv)) return rv;
171 return controller->QueryInterface(aIID, aResult);
174 // Constructor for a command table that is pref-filled with HTML editor commands
175 static NS_METHOD
176 nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
177 void **aResult)
179 nsresult rv;
180 nsCOMPtr<nsIControllerCommandTable> commandTable =
181 do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
182 if (NS_FAILED(rv)) return rv;
184 rv = nsComposerController::RegisterHTMLEditorCommands(commandTable);
185 if (NS_FAILED(rv)) return rv;
187 // we don't know here whether we're being created as an instance,
188 // or a service, so we can't become immutable
190 return commandTable->QueryInterface(aIID, aResult);
194 // Constructor for a command table that is pref-filled with HTML editor doc state commands
195 static NS_METHOD
196 nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
197 void **aResult)
199 nsresult rv;
200 nsCOMPtr<nsIControllerCommandTable> commandTable =
201 do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
202 if (NS_FAILED(rv)) return rv;
204 rv = nsComposerController::RegisterEditorDocStateCommands(commandTable);
205 if (NS_FAILED(rv)) return rv;
207 // we don't know here whether we're being created as an instance,
208 // or a service, so we can't become immutable
210 return commandTable->QueryInterface(aIID, aResult);
213 ////////////////////////////////////////////////////////////////////////
214 // Define a table of CIDs implemented by this module along with other
215 // information like the function to create an instance, contractid, and
216 // class name.
218 static const nsModuleComponentInfo components[] = {
220 { "HTML Editor Controller", NS_HTMLEDITORCONTROLLER_CID,
221 "@mozilla.org/editor/htmleditorcontroller;1",
222 nsHTMLEditorControllerConstructor, },
224 { "HTML Editor DocState Controller", NS_EDITORDOCSTATECONTROLLER_CID,
225 "@mozilla.org/editor/editordocstatecontroller;1",
226 nsHTMLEditorDocStateControllerConstructor, },
228 { "HTML Editor command table", NS_HTMLEDITOR_COMMANDTABLE_CID,
229 "", // no point using a contract-ID
230 nsHTMLEditorCommandTableConstructor, },
232 { "HTML Editor doc state command table", NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID,
233 "", // no point using a contract-ID
234 nsHTMLEditorDocStateCommandTableConstructor, },
236 { "Editing Session", NS_EDITINGSESSION_CID,
237 "@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, },
239 { "Editor Spell Checker", NS_EDITORSPELLCHECK_CID,
240 "@mozilla.org/editor/editorspellchecker;1",
241 nsEditorSpellCheckConstructor,},
243 { "TxtSrv Filter", NS_COMPOSERTXTSRVFILTER_CID,
244 COMPOSER_TXTSRVFILTER_CONTRACTID,
245 nsComposeTxtSrvFilterConstructorForComposer, },
247 { "TxtSrv Filter For Mail", NS_COMPOSERTXTSRVFILTERMAIL_CID,
248 COMPOSER_TXTSRVFILTERMAIL_CONTRACTID,
249 nsComposeTxtSrvFilterConstructorForMail, },
252 ////////////////////////////////////////////////////////////////////////
253 // Implement the NSGetModule() exported function for your module
254 // and the entire implementation of the module object.
256 NS_IMPL_NSGETMODULE(nsComposerModule, components)