gecko-dev/layout/build/nsLayoutModule.cpp

335 строки
8.9 KiB
C++
Исходник Обычный вид История

1999-09-28 04:44:47 +04:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1999-09-28 04:44:47 +04:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1999-09-28 04:44:47 +04:00
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
1999-09-28 04:44:47 +04:00
*/
2000-01-25 00:28:28 +03:00
#include "nspr.h"
#include "nsString.h"
1999-09-28 04:44:47 +04:00
#include "nsCOMPtr.h"
#include "nsLayoutModule.h"
#include "nsLayoutCID.h"
#include "nsIComponentManager.h"
#include "nsNetUtil.h"
1999-09-28 04:44:47 +04:00
#include "nsICSSStyleSheet.h"
#include "nsHTMLAtoms.h"
#include "nsCSSKeywords.h" // to addref/release table
#include "nsCSSProps.h" // to addref/release table
#include "nsCSSAtoms.h" // to addref/release table
#include "nsColorNames.h" // to addref/release table
#ifdef INCLUDE_XUL
#include "nsXULAtoms.h"
#endif
1999-10-02 15:01:41 +04:00
//MathML Mod - RBS
#ifdef MOZ_MATHML
#include "nsMathMLAtoms.h"
#include "nsMathMLOperators.h"
#endif
1999-09-28 04:44:47 +04:00
#include "nsLayoutAtoms.h"
#include "nsDOMCID.h"
#include "nsINameSpaceManager.h"
#include "nsINodeInfo.h"
#include "nsIElementFactory.h"
1999-09-28 04:44:47 +04:00
#include "nsIDocumentEncoder.h"
#include "nsIContentSerializer.h"
#include "nsIHTMLToTextSink.h"
1999-09-28 04:44:47 +04:00
#include "nsIGenericFactory.h"
// SVG
#ifdef MOZ_SVG
#include "nsSVGAtoms.h"
#endif
1999-09-28 04:44:47 +04:00
// XXX
#include "nsIServiceManager.h"
#include "nsTextTransformer.h"
#ifdef INCLUDE_XUL
#include "nsBulletinBoardLayout.h"
#include "nsRepeatService.h"
#include "nsSprocketLayout.h"
#include "nsStackLayout.h"
#endif
#include "nsContentPolicyUtils.h"
1999-09-28 04:44:47 +04:00
static nsLayoutModule *gModule = NULL;
extern "C" NS_EXPORT
nsresult NSGETMODULE_ENTRY_POINT(nsLayoutModule)(nsIComponentManager *servMgr,
2000-01-25 00:28:28 +03:00
nsIFile* location,
1999-09-28 04:44:47 +04:00
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsLayoutModule: Module already created.");
// Create an initialize the layout module instance
nsLayoutModule *m = new nsLayoutModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
1999-09-28 04:44:47 +04:00
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
//----------------------------------------------------------------------
nsICSSStyleSheet* nsLayoutModule::gUAStyleSheet = nsnull;
1999-09-28 04:44:47 +04:00
nsLayoutModule::nsLayoutModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsLayoutModule::~nsLayoutModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsLayoutModule, NS_GET_IID(nsIModule))
1999-09-28 04:44:47 +04:00
// Perform our one-time intialization for this module
nsresult
nsLayoutModule::Initialize()
{
nsresult rv = NS_OK;
1999-09-28 04:44:47 +04:00
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
1999-09-28 04:44:47 +04:00
// Register all of our atoms once
nsCSSAtoms::AddRefAtoms();
nsCSSKeywords::AddRefTable();
nsCSSProps::AddRefTable();
nsColorNames::AddRefTable();
nsHTMLAtoms::AddRefAtoms();
1999-10-01 01:14:14 +04:00
nsLayoutAtoms::AddRefAtoms();
1999-09-28 04:44:47 +04:00
#ifdef INCLUDE_XUL
nsXULAtoms::AddRefAtoms();
#endif
1999-10-02 15:01:41 +04:00
//MathML Mod - RBS
#ifdef MOZ_MATHML
nsMathMLOperators::AddRefTable();
nsMathMLAtoms::AddRefAtoms();
#endif
1999-09-28 04:44:47 +04:00
// SVG
#ifdef MOZ_SVG
nsSVGAtoms::AddRefAtoms();
#endif
rv = nsTextTransformer::Initialize();
if (NS_FAILED(rv)) {
return rv;
}
1999-09-28 04:44:47 +04:00
return rv;
}
// Shutdown this module, releasing all of the module resources
void
nsLayoutModule::Shutdown()
{
if (!mInitialized) {
return;
}
#ifdef INCLUDE_XUL
nsBulletinBoardLayout::Shutdown();
nsRepeatService::Shutdown();
nsSprocketLayout::Shutdown();
nsStackLayout::Shutdown();
#endif
1999-09-28 04:44:47 +04:00
// Release all of our atoms
nsColorNames::ReleaseTable();
nsCSSProps::ReleaseTable();
nsCSSKeywords::ReleaseTable();
nsCSSAtoms::ReleaseAtoms();
nsHTMLAtoms::ReleaseAtoms();
1999-10-01 01:14:14 +04:00
nsLayoutAtoms::ReleaseAtoms();
1999-09-28 04:44:47 +04:00
#ifdef INCLUDE_XUL
nsXULAtoms::ReleaseAtoms();
#endif
1999-10-02 15:01:41 +04:00
//MathML Mod - RBS
#ifdef MOZ_MATHML
nsMathMLOperators::ReleaseTable();
nsMathMLAtoms::ReleaseAtoms();
#endif
// SVG
#ifdef MOZ_SVG
nsSVGAtoms::ReleaseAtoms();
#endif
1999-09-28 04:44:47 +04:00
nsTextTransformer::Shutdown();
NS_IF_RELEASE(gUAStyleSheet);
1999-09-28 04:44:47 +04:00
}
NS_IMETHODIMP
nsLayoutModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
}
nsCOMPtr<nsIFactory> f = new nsLayoutFactory(aClass);
1999-09-28 04:44:47 +04:00
if (!f) {
return NS_ERROR_OUT_OF_MEMORY;
}
return f->QueryInterface(aIID, r_classObj);
1999-09-28 04:44:47 +04:00
}
//----------------------------------------
struct Components {
const char* mDescription;
nsID mCID;
const char* mContractID;
1999-09-28 04:44:47 +04:00
};
// The HTML namespace.
1999-09-28 04:44:47 +04:00
// The list of components we register
static Components gComponents[] = {
{ "Frame utility", NS_FRAME_UTIL_CID, nsnull, },
{ "Print preview context", NS_PRINT_PREVIEW_CONTEXT_CID, nsnull, },
{ "Layout debugger", NS_LAYOUT_DEBUGGER_CID, nsnull, },
{ "CSS Frame Constructor", NS_CSSFRAMECONSTRUCTOR_CID, nsnull, },
{ "Frame Traversal", NS_FRAMETRAVERSAL_CID, nsnull, },
{ "Layout History State", NS_LAYOUT_HISTORY_STATE_CID, nsnull, },
1999-09-28 04:44:47 +04:00
// XXX ick
{ "Presentation shell", NS_PRESSHELL_CID, nsnull, },
{ "Presentation state", NS_PRESSTATE_CID, nsnull, },
{ "Galley context", NS_GALLEYCONTEXT_CID, nsnull, },
{ "Print context", NS_PRINTCONTEXT_CID, nsnull, },
1999-09-28 04:44:47 +04:00
// XXX end ick
{ "XUL Box Object", NS_BOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject;1" },
{ "XUL Tree Box Object", NS_TREEBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-tree;1" },
{ "XUL Menu Box Object", NS_MENUBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-menu;1" },
{ "XUL PopupSet Box Object", NS_POPUPSETBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-popupset;1" },
{ "XUL Browser Box Object", NS_BROWSERBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-browser;1" },
{ "XUL Editor Box Object", NS_EDITORBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-editor;1" },
{ "XUL Iframe Object", NS_IFRAMEBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-iframe;1" },
{ "XUL ScrollBox Object", NS_SCROLLBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-scrollbox;1" },
{ "XUL Outliner Box Object", NS_OUTLINERBOXOBJECT_CID, "@mozilla.org/layout/xul-boxobject-outliner;1" },
{ "AutoCopy Service", NS_AUTOCOPYSERVICE_CID, "@mozilla.org/autocopy;1" }
1999-09-28 04:44:47 +04:00
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsLayoutModule::RegisterSelf(nsIComponentManager *aCompMgr,
2000-01-25 00:28:28 +03:00
nsIFile* aPath,
1999-09-28 04:44:47 +04:00
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering layout components\n");
#endif
1999-09-28 04:44:47 +04:00
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentWithType(cp->mCID, cp->mDescription,
cp->mContractID, aPath,
registryLocation, PR_TRUE,
PR_TRUE, componentType);
1999-09-28 04:44:47 +04:00
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLayoutModule: unable to register %s component => %x\n",
1999-09-28 04:44:47 +04:00
cp->mDescription, rv);
#endif
1999-09-28 04:44:47 +04:00
break;
}
cp++;
}
rv = RegisterDocumentFactories(aCompMgr, aPath, registryLocation,
componentType);
1999-09-28 04:44:47 +04:00
return rv;
}
NS_IMETHODIMP
nsLayoutModule::UnregisterSelf(nsIComponentManager* aCompMgr,
2000-01-25 00:28:28 +03:00
nsIFile* aPath,
1999-09-28 04:44:47 +04:00
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering layout components\n");
#endif
1999-09-28 04:44:47 +04:00
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLayoutModule: unable to unregister %s component => %x\n",
1999-09-28 04:44:47 +04:00
cp->mDescription, rv);
#endif
1999-09-28 04:44:47 +04:00
}
cp++;
}
UnregisterDocumentFactories(aCompMgr, aPath);
return NS_OK;
}
NS_IMETHODIMP
nsLayoutModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}