1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Mozilla platform.
16 * The Initial Developer of the Original Code is
17 * Benjamin Smedberg <benjamin@smedbergs.us>.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsLayoutStatics.h"
41 #include "nsAttrValue.h"
42 #include "nsAutoCopyListener.h"
43 #include "nsColorNames.h"
44 #include "nsComputedDOMStyle.h"
45 #include "nsContentDLF.h"
46 #include "nsContentUtils.h"
47 #include "nsCSSAnonBoxes.h"
48 #include "nsCSSFrameConstructor.h"
49 #include "nsCSSKeywords.h"
50 #include "nsCSSLoader.h"
51 #include "nsCSSProps.h"
52 #include "nsCSSPseudoClasses.h"
53 #include "nsCSSPseudoElements.h"
54 #include "nsCSSRendering.h"
55 #include "nsCSSScanner.h"
56 #include "nsICSSStyleSheet.h"
57 #include "nsDOMAttribute.h"
58 #include "nsDOMClassInfo.h"
59 #include "nsDOMScriptObjectFactory.h"
60 #include "nsEventListenerManager.h"
62 #include "nsGenericElement.h" // for nsDOMEventRTTearoff
63 #include "nsStyledElement.h"
64 #include "nsGlobalWindow.h"
65 #include "nsGkAtoms.h"
66 #include "nsImageFrame.h"
67 #include "nsLayoutStylesheetCache.h"
68 #include "nsNodeInfo.h"
70 #include "nsRepeatService.h"
71 #include "nsSpaceManager.h"
72 #include "nsSprocketLayout.h"
73 #include "nsStackLayout.h"
74 #include "nsStyleSet.h"
75 #include "nsTextControlFrame.h"
76 #include "nsXBLWindowKeyHandler.h"
77 #include "txMozillaXSLTProcessor.h"
78 #include "nsDOMStorage.h"
79 #include "nsCellMap.h"
80 #include "nsTextFrameTextRunCache.h"
81 #include "nsCCUncollectableMarker.h"
82 #include "nsTextFragment.h"
83 #include "nsCSSRuleProcessor.h"
84 #include "nsXMLHttpRequest.h"
85 #include "nsIFocusEventSuppressor.h"
88 #include "nsXULPopupManager.h"
89 #include "nsXULContentUtils.h"
90 #include "nsXULElement.h"
91 #include "nsXULPrototypeCache.h"
92 #include "nsXULTooltipListener.h"
94 #ifndef MOZ_NO_INSPECTOR_APIS
95 #include "inDOMView.h"
100 #include "nsMathMLAtoms.h"
101 #include "nsMathMLOperators.h"
105 PRBool
NS_SVGEnabled();
108 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
109 #include "nsHTMLEditor.h"
110 #include "nsTextServicesDocument.h"
114 #include "nsVideoDecoder.h"
118 #include "nsAudioStream.h"
119 #include "nsVideoDecoder.h"
123 #include "nsTraceRefcnt.h"
125 #include "nsCycleCollector.h"
127 static nsrefcnt sLayoutStaticRefcnt
;
130 nsLayoutStatics::Initialize()
132 NS_ASSERTION(sLayoutStaticRefcnt
== 0,
133 "nsLayoutStatics isn't zero!");
135 sLayoutStaticRefcnt
= 1;
136 NS_LOG_ADDREF(&sLayoutStaticRefcnt
, sLayoutStaticRefcnt
,
137 "nsLayoutStatics", 1);
141 // Register all of our atoms once
142 nsCSSAnonBoxes::AddRefAtoms();
143 nsCSSPseudoClasses::AddRefAtoms();
144 nsCSSPseudoElements::AddRefAtoms();
145 nsCSSKeywords::AddRefTable();
146 nsCSSProps::AddRefTable();
147 nsColorNames::AddRefTable();
148 nsGkAtoms::AddRefAtoms();
150 nsDOMScriptObjectFactory::Startup();
151 rv
= nsContentUtils::Init();
153 NS_ERROR("Could not initialize nsContentUtils");
157 rv
= nsAttrValue::Init();
159 NS_ERROR("Could not initialize nsAttrValue");
163 rv
= nsTextFragment::Init();
165 NS_ERROR("Could not initialize nsTextFragment");
169 rv
= nsCellMap::Init();
171 NS_ERROR("Could not initialize nsCellMap");
175 rv
= nsCSSRendering::Init();
177 NS_ERROR("Could not initialize nsCSSRendering");
181 rv
= nsTextFrameTextRunCache::Init();
183 NS_ERROR("Could not initialize textframe textrun cache");
188 rv
= nsXULContentUtils::Init();
190 NS_ERROR("Could not initialize nsXULContentUtils");
194 #ifndef MOZ_NO_INSPECTOR_APIS
195 inDOMView::InitAtoms();
201 nsMathMLOperators::AddRefTable();
206 nsContentDLF::RegisterSVG();
209 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
210 nsEditProperty::RegisterAtoms();
211 nsTextServicesDocument::RegisterAtoms();
215 nsFrame::DisplayReflowStartup();
217 nsDOMAttribute::Initialize();
219 rv
= txMozillaXSLTProcessor::Startup();
221 NS_ERROR("Could not initialize txMozillaXSLTProcessor");
225 rv
= nsDOMStorageManager::Initialize();
227 NS_ERROR("Could not initialize nsDOMStorageManager");
232 rv
= nsCCUncollectableMarker::Init();
234 NS_ERROR("Could not initialize nsCCUncollectableMarker");
240 rv
= nsXULPopupManager::Init();
242 NS_ERROR("Could not initialize nsXULPopupManager");
248 rv
= nsVideoDecoder::InitLogger();
250 NS_ERROR("Could not initialize nsVideoDecoder");
257 rv
= nsAudioStream::InitLibrary();
259 NS_ERROR("Could not initialize nsAudioStream");
268 nsLayoutStatics::Shutdown()
271 nsXULPopupManager::Shutdown();
273 nsDOMStorageManager::Shutdown();
274 txMozillaXSLTProcessor::Shutdown();
275 nsDOMAttribute::Shutdown();
276 nsDOMEventRTTearoff::Shutdown();
277 nsEventListenerManager::Shutdown();
278 nsContentList::Shutdown();
279 nsComputedDOMStyle::Shutdown();
280 CSSLoaderImpl::Shutdown();
281 nsCSSRuleProcessor::FreeSystemMetrics();
282 nsTextFrameTextRunCache::Shutdown();
283 nsCSSRendering::Shutdown();
285 nsFrame::DisplayReflowShutdown();
287 nsCellMap::Shutdown();
289 // Release all of our atoms
290 nsColorNames::ReleaseTable();
291 nsCSSProps::ReleaseTable();
292 nsCSSKeywords::ReleaseTable();
293 nsRepeatService::Shutdown();
294 nsStackLayout::Shutdown();
298 nsXULContentUtils::Finish();
299 nsXULElement::ReleaseGlobals();
300 nsXULPrototypeCache::ReleaseGlobals();
301 nsXULPrototypeElement::ReleaseGlobals();
302 nsSprocketLayout::Shutdown();
306 nsMathMLOperators::ReleaseTable();
309 nsCSSFrameConstructor::ReleaseGlobals();
310 nsSpaceManager::Shutdown();
311 nsImageFrame::ReleaseGlobals();
313 nsCSSScanner::ReleaseGlobals();
315 NS_IF_RELEASE(nsContentDLF::gUAStyleSheet
);
316 NS_IF_RELEASE(nsRuleNode::gLangService
);
317 nsStyledElement::Shutdown();
319 nsTextFragment::Shutdown();
321 nsAttrValue::Shutdown();
322 nsContentUtils::Shutdown();
323 nsNodeInfo::ClearCache();
324 nsLayoutStylesheetCache::Shutdown();
325 NS_NameSpaceManagerShutdown();
326 nsStyleSet::FreeGlobals();
328 nsGlobalWindow::ShutDown();
329 nsDOMClassInfo::ShutDown();
330 nsTextControlFrame::ShutDown();
331 nsXBLWindowKeyHandler::ShutDown();
332 nsAutoCopyListener::Shutdown();
334 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
335 nsHTMLEditor::Shutdown();
336 nsTextServicesDocument::Shutdown();
339 NS_ShutdownFocusSuppressor();
342 nsAudioStream::ShutdownLibrary();
347 nsLayoutStatics::AddRef()
349 NS_ASSERTION(sLayoutStaticRefcnt
,
350 "nsLayoutStatics already dropped to zero!");
352 ++sLayoutStaticRefcnt
;
353 NS_LOG_ADDREF(&sLayoutStaticRefcnt
, sLayoutStaticRefcnt
,
354 "nsLayoutStatics", 1);
358 nsLayoutStatics::Release()
360 --sLayoutStaticRefcnt
;
361 NS_LOG_RELEASE(&sLayoutStaticRefcnt
, sLayoutStaticRefcnt
,
364 if (!sLayoutStaticRefcnt
)