diff --git a/mozilla/content/xul/content/src/nsXULAtoms.cpp b/mozilla/content/xul/content/src/nsXULAtoms.cpp index 3ec0538246a..653e4f1f20c 100644 --- a/mozilla/content/xul/content/src/nsXULAtoms.cpp +++ b/mozilla/content/xul/content/src/nsXULAtoms.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- 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 @@ -10,70 +10,65 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is Mozilla Communicator client code. + * The Original Code is mozilla.org code. * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are + * 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. * - * Original Author(s): - * Chris Waterson + * Original Author: David W. Hyatt (hyatt@netscape.com) * * Contributor(s): - * - */ - -/* - - Back-end for commonly used XUL atoms. - */ +#include "nsString.h" +#include "nsINameSpaceManager.h" #include "nsXULAtoms.h" -#ifdef NS_XULATOM -#undef NS_XULATOM -#undef NS_XULATOM2 -#endif +static const char kXULNameSpace[] = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -#define NS_XULATOM(__atom) nsIAtom* nsXULAtoms::__atom -#define NS_XULATOM2(__atom, __value) nsIAtom* nsXULAtoms::__atom -#include "nsXULAtoms.inc" +PRInt32 nsXULAtoms::nameSpaceID; -nsrefcnt nsXULAtoms::gRefCnt = 0; -nsIAtom* nsXULAtoms::Template; +// define storage for all atoms +#define XUL_ATOM(_name, _value) nsIAtom* nsXULAtoms::_name; +#include "nsXULAtomList.h" +#undef XUL_ATOM -nsrefcnt -nsXULAtoms::AddRef() -{ - if (++gRefCnt == 1) { -#undef NS_XULATOM -#undef NS_XULATOM2 -#define NS_XULATOM(__atom) __atom = NS_NewAtom(#__atom) -#define NS_XULATOM2(__atom, __value) __atom = NS_NewAtom(__value) -#include "nsXULAtoms.inc" - Template = NS_NewAtom("template"); +static nsrefcnt gRefCnt = 0; +static nsINameSpaceManager* gNameSpaceManager; + +void nsXULAtoms::AddRefAtoms() { + + if (gRefCnt == 0) { + /* XUL Atoms registers the XUL name space ID because it's a convenient + place to do this, if you don't want a permanent, "well-known" ID. + */ + if (NS_SUCCEEDED(NS_NewNameSpaceManager(&gNameSpaceManager))) { +// gNameSpaceManager->CreateRootNameSpace(namespace); + nsAutoString nameSpace; nameSpace.AssignWithConversion(kXULNameSpace); + gNameSpaceManager->RegisterNameSpace(nameSpace, nameSpaceID); + } else { + NS_ASSERTION(0, "failed to create xul atoms namespace manager"); } - return gRefCnt; + // now register the atoms +#define XUL_ATOM(_name, _value) _name = NS_NewAtom(_value); +#include "nsXULAtomList.h" +#undef XUL_ATOM + } + ++gRefCnt; } +void nsXULAtoms::ReleaseAtoms() { -nsrefcnt -nsXULAtoms::Release() -{ - if (--gRefCnt == 0) { -#undef NS_XULATOM -#undef NS_XULATOM2 -#define NS_XULATOM(__atom) NS_RELEASE(__atom) -#define NS_XULATOM2(__atom, __value) NS_RELEASE(__atom) -#include "nsXULAtoms.inc" + NS_PRECONDITION(gRefCnt != 0, "bad release of xul atoms"); + if (--gRefCnt == 0) { +#define XUL_ATOM(_name, _value) NS_RELEASE(_name); +#include "nsXULAtomList.h" +#undef XUL_ATOM - NS_RELEASE(Template); - } - - return gRefCnt; + NS_IF_RELEASE(gNameSpaceManager); + } } - diff --git a/mozilla/content/xul/content/src/nsXULAtoms.h b/mozilla/content/xul/content/src/nsXULAtoms.h index 87ac1e85e00..93b2b7d53e9 100644 --- a/mozilla/content/xul/content/src/nsXULAtoms.h +++ b/mozilla/content/xul/content/src/nsXULAtoms.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- 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 @@ -10,53 +10,51 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is Mozilla Communicator client code. + * The Original Code is mozilla.org code. * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are + * 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. * - * Original Author(s): - * Chris Waterson + * Original Author: David W. Hyatt (hyatt@netscape.com) * * Contributor(s): - * */ +#ifndef nsXULAtoms_h___ +#define nsXULAtoms_h___ -/* - - Header file used to include the commonly-used atoms in the XUL - code. Actual atom additions and removal should be performed on - nsXULAtoms.inc. - - */ - - -#ifndef nsXULAtoms_h__ -#define nsXULAtoms_h__ - +#include "prtypes.h" #include "nsIAtom.h" -#ifdef NS_XULATOM -#undef NS_XULATOM -#endif - -#define NS_XULATOM(__atom) static nsIAtom* __atom -#define NS_XULATOM2(__atom, __value) static nsIAtom* __atom +class nsINameSpaceManager; +/** + * This class wraps up the creation and destruction of the standard + * set of xul atoms used during normal xul handling. This object + * is created when the first xul content object is created, and + * destroyed when the last such content object is destroyed. + */ class nsXULAtoms { -protected: - static nsrefcnt gRefCnt; - public: - static nsrefcnt AddRef(); - static nsrefcnt Release(); -#include "nsXULAtoms.inc" + static void AddRefAtoms(); + static void ReleaseAtoms(); + + // XUL namespace ID, good for the life of the nsXULAtoms object + static PRInt32 nameSpaceID; + + /* Declare all atoms + + The atom names and values are stored in nsCSSAtomList.h and + are brought to you by the magic of C preprocessing + + Add new atoms to nsCSSAtomList and all support logic will be auto-generated + */ +#define XUL_ATOM(_name, _value) static nsIAtom* _name; +#include "nsXULAtomList.h" +#undef XUL_ATOM - static nsIAtom* Template; // XXX because |template| is a keyword }; - -#endif +#endif /* nsXULAtoms_h___ */