Back to index

lightning-sunbird  0.9+nobinonly
nsLayoutStatics.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla platform.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Benjamin Smedberg <benjamin@smedbergs.us>.
00018  *
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsLayoutStatics.h"
00039 #include "nscore.h"
00040 
00041 #include "nsAttrValue.h"
00042 #include "nsAutoCopyListener.h"
00043 #include "nsColorNames.h"
00044 #include "nsComputedDOMStyle.h"
00045 #include "nsContentDLF.h"
00046 #include "nsContentUtils.h"
00047 #include "nsCSSAnonBoxes.h"
00048 #include "nsCSSFrameConstructor.h"
00049 #include "nsCSSKeywords.h"
00050 #include "nsCSSLoader.h"
00051 #include "nsCSSProps.h"
00052 #include "nsCSSPseudoClasses.h"
00053 #include "nsCSSPseudoElements.h"
00054 #include "nsCSSScanner.h"
00055 #include "nsICSSStyleSheet.h"
00056 #include "nsDOMAttribute.h"
00057 #include "nsDOMClassInfo.h"
00058 #include "nsEventListenerManager.h"
00059 #include "nsFrame.h"
00060 #include "nsGenericElement.h"  // for nsDOMEventRTTearoff
00061 #include "nsGenericHTMLElement.h"
00062 #include "nsGlobalWindow.h"
00063 #include "nsHTMLAtoms.h"
00064 #include "nsImageFrame.h"
00065 #include "nsJSEnvironment.h"
00066 #include "nsLayoutAtoms.h"
00067 #include "nsLayoutStylesheetCache.h"
00068 #include "nsNodeInfo.h"
00069 #include "nsRange.h"
00070 #include "nsRepeatService.h"
00071 #include "nsSpaceManager.h"
00072 #include "nsSprocketLayout.h"
00073 #include "nsStackLayout.h"
00074 #include "nsStyleSet.h"
00075 #include "nsTextControlFrame.h"
00076 #include "nsTextTransformer.h"
00077 #include "nsXBLAtoms.h"
00078 #include "nsXBLWindowKeyHandler.h"
00079 #include "nsDOMStorage.h"
00080 
00081 #ifdef MOZ_XUL
00082 #include "nsXULContentUtils.h"
00083 #include "nsXULElement.h"
00084 #endif
00085 
00086 #ifdef MOZ_MATHML
00087 #include "nsMathMLAtoms.h"
00088 #include "nsMathMLOperators.h"
00089 #endif
00090 
00091 #ifdef MOZ_SVG
00092 #include "nsSVGAtoms.h"
00093 #include "nsSVGUtils.h"
00094 #endif
00095 
00096 #ifndef MOZ_NO_INSPECTOR_APIS
00097 #include "inDOMView.h"
00098 #endif
00099 
00100 #include "nsError.h"
00101 #include "nsTraceRefcnt.h"
00102 
00103 static nsrefcnt sLayoutStaticRefcnt;
00104 
00105 nsresult
00106 nsLayoutStatics::Initialize()
00107 {
00108   NS_ASSERTION(sLayoutStaticRefcnt == 0,
00109                "nsLayoutStatics isn't zero!");
00110 
00111   sLayoutStaticRefcnt = 1;
00112   NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
00113                 "nsLayoutStatics", 1);
00114 
00115   nsresult rv;
00116 
00117   nsJSEnvironment::Startup();
00118   rv = nsContentUtils::Init();
00119   if (NS_FAILED(rv)) {
00120     NS_ERROR("Could not initialize nsContentUtils");
00121 
00122     Shutdown();
00123 
00124     return rv;
00125   }
00126   rv = nsAttrValue::Init();
00127   if (NS_FAILED(rv)) {
00128     NS_ERROR("Could not initialize nsAttrValue");
00129 
00130     Shutdown();
00131 
00132     return rv;
00133   }
00134 
00135   // Register all of our atoms once
00136   nsCSSAnonBoxes::AddRefAtoms();
00137   nsCSSPseudoClasses::AddRefAtoms();
00138   nsCSSPseudoElements::AddRefAtoms();
00139   nsCSSKeywords::AddRefTable();
00140   nsCSSProps::AddRefTable();
00141   nsColorNames::AddRefTable();
00142   nsHTMLAtoms::AddRefAtoms();
00143   nsXBLAtoms::AddRefAtoms();
00144   nsLayoutAtoms::AddRefAtoms();
00145   nsXULAtoms::AddRefAtoms();
00146 
00147 #ifndef MOZ_NO_INSPECTOR_APIS
00148   inDOMView::InitAtoms();
00149 #endif
00150 
00151 #ifdef MOZ_XUL
00152   rv = nsXULContentUtils::Init();
00153   if (NS_FAILED(rv)) {
00154     NS_ERROR("Could not initialize nsXULContentUtils");
00155 
00156     Shutdown();
00157 
00158     return rv;
00159   }
00160 #endif
00161 
00162 #ifdef MOZ_MATHML
00163   nsMathMLOperators::AddRefTable();
00164   nsMathMLAtoms::AddRefAtoms();
00165 #endif
00166 
00167 #ifdef MOZ_SVG
00168   if (nsSVGUtils::SVGEnabled())
00169     nsContentDLF::RegisterSVG();
00170   nsSVGAtoms::AddRefAtoms();
00171 #ifdef MOZ_SVG_RENDERER_LIBART
00172   NS_InitSVGRendererLibartGlobals();
00173 #endif
00174 #ifdef MOZ_SVG_RENDERER_GDIPLUS
00175   NS_InitSVGRendererGDIPlusGlobals();
00176 #endif
00177 #endif
00178 
00179 #ifdef DEBUG
00180   nsFrame::DisplayReflowStartup();
00181 #endif
00182   rv = nsTextTransformer::Initialize();
00183   NS_ENSURE_SUCCESS(rv, rv);
00184 
00185   nsDOMAttribute::Initialize();
00186 
00187   rv = nsDOMStorageManager::Initialize();
00188   if (NS_FAILED(rv)) {
00189     NS_ERROR("Could not initialize nsDOMStorageManager");
00190     return rv;
00191   }
00192 
00193   return NS_OK;
00194 }
00195 
00196 void
00197 nsLayoutStatics::Shutdown()
00198 {
00199   nsDOMStorageManager::Shutdown();
00200   nsDOMAttribute::Shutdown();
00201   nsGenericElement::Shutdown();
00202   nsEventListenerManager::Shutdown();
00203   nsContentList::Shutdown();
00204   nsComputedDOMStyle::Shutdown();
00205   CSSLoaderImpl::Shutdown();
00206 #ifdef DEBUG
00207   nsFrame::DisplayReflowShutdown();
00208 #endif
00209 
00210   // Release all of our atoms
00211   nsColorNames::ReleaseTable();
00212   nsCSSProps::ReleaseTable();
00213   nsCSSKeywords::ReleaseTable();
00214   nsRepeatService::Shutdown();
00215   nsStackLayout::Shutdown();
00216   nsBox::Shutdown();
00217 
00218 #ifdef MOZ_XUL
00219   nsXULContentUtils::Finish();
00220   nsXULElement::ReleaseGlobals();
00221   nsXULPrototypeElement::ReleaseGlobals();
00222   nsXULPrototypeScript::ReleaseGlobals();
00223   nsSprocketLayout::Shutdown();
00224 #endif
00225 
00226 #ifdef MOZ_MATHML
00227   nsMathMLOperators::ReleaseTable();
00228 #endif
00229 
00230 #ifdef MOZ_SVG
00231 #ifdef MOZ_SVG_RENDERER_LIBART
00232   NS_FreeSVGRendererLibartGlobals();
00233 #endif
00234 #ifdef MOZ_SVG_RENDERER_GDIPLUS
00235   NS_FreeSVGRendererGDIPlusGlobals();
00236 #endif
00237 #endif
00238 
00239   nsCSSFrameConstructor::ReleaseGlobals();
00240   nsTextTransformer::Shutdown();
00241   nsSpaceManager::Shutdown();
00242   nsImageFrame::ReleaseGlobals();
00243 
00244   nsCSSScanner::ReleaseGlobals();
00245 
00246   NS_IF_RELEASE(nsContentDLF::gUAStyleSheet);
00247   NS_IF_RELEASE(nsRuleNode::gLangService);
00248   nsGenericHTMLElement::Shutdown();
00249 
00250   nsAttrValue::Shutdown();
00251   nsContentUtils::Shutdown();
00252   nsLayoutStylesheetCache::Shutdown();
00253   NS_NameSpaceManagerShutdown();
00254   nsStyleSet::FreeGlobals();
00255 
00256   nsGlobalWindow::ShutDown();
00257   nsDOMClassInfo::ShutDown();
00258   nsTextControlFrame::ShutDown();
00259   nsXBLWindowKeyHandler::ShutDown();
00260   nsAutoCopyListener::Shutdown();
00261 }
00262 
00263 void
00264 nsLayoutStatics::AddRef()
00265 {
00266   NS_ASSERTION(sLayoutStaticRefcnt,
00267                "nsLayoutStatics already dropped to zero!");
00268 
00269   ++sLayoutStaticRefcnt;
00270   NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
00271                 "nsLayoutStatics", 1);
00272 }
00273 
00274 void
00275 nsLayoutStatics::Release()
00276 {
00277   --sLayoutStaticRefcnt;
00278   NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
00279                  "nsLayoutStatics");
00280 
00281   if (!sLayoutStaticRefcnt)
00282     Shutdown();
00283 }