diff --git a/mozilla/content/base/src/nsAtomListUtils.cpp b/mozilla/content/base/src/nsAtomListUtils.cpp new file mode 100644 index 00000000000..ab8b161f74e --- /dev/null +++ b/mozilla/content/base/src/nsAtomListUtils.cpp @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Original Code is nsAtomListUtils.h . + * + * The Initial Developer of the Original Code is L. David Baron. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * L. David Baron (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsAtomListUtils.h" +#include "nsIAtom.h" + +/* static */ void +nsAtomListUtils::AddRefAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aCount; + info != info_end; ++info) { + *(info->mAtom) = NS_NewPermanentAtom(info->mString); + } +} + +/* static */ void +nsAtomListUtils::ReleaseAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aCount; + info != info_end; ++info) { + NS_RELEASE(*(info->mAtom)); + } +} + +/* static */ PRBool +nsAtomListUtils::IsMember(nsIAtom *aAtom, + const nsAtomListInfo* aInfo, + PRUint32 aInfoCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aInfoCount; + info != info_end; ++info) { + if (aAtom == *(info->mAtom)) + return PR_TRUE; + } + return PR_FALSE; +} diff --git a/mozilla/content/base/src/nsAtomListUtils.h b/mozilla/content/base/src/nsAtomListUtils.h new file mode 100644 index 00000000000..4bee33a7ad2 --- /dev/null +++ b/mozilla/content/base/src/nsAtomListUtils.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Original Code is nsAtomListUtils.h . + * + * The Initial Developer of the Original Code is L. David Baron. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * L. David Baron (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsAtomListUtils_h__ +#define nsAtomListUtils_h__ + +#include "prtypes.h" + +class nsIAtom; + +#define MOZ_ARRAY_LENGTH(a_) (sizeof(a_)/sizeof(a_[0])) + +struct nsAtomListInfo { + nsIAtom** mAtom; + const char* mString; +}; + +class nsAtomListUtils { +public: + static void AddRefAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount); + static void ReleaseAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount); + + static PRBool IsMember(nsIAtom *aAtom, + const nsAtomListInfo* aInfo, + PRUint32 aInfoCount); +}; + +#endif /* !defined(nsAtomListUtils_h__) */ diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.cpp b/mozilla/content/html/content/src/nsHTMLAtoms.cpp index 0fd9bb7c0cd..b526e18123b 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.cpp +++ b/mozilla/content/html/content/src/nsHTMLAtoms.cpp @@ -36,22 +36,26 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsHTMLAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define HTML_ATOM(_name, _value) nsIAtom* nsHTMLAtoms::_name; #include "nsHTMLAtomList.h" #undef HTML_ATOM - static nsrefcnt gRefCnt; +static const nsAtomListInfo HTMLAtoms_info[] = { +#define HTML_ATOM(name_, value_) { &nsHTMLAtoms::name_, value_ }, +#include "nsHTMLAtomList.h" +#undef HTML_ATOM +}; + void nsHTMLAtoms::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define HTML_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsHTMLAtomList.h" -#undef HTML_ATOM + nsAtomListUtils::AddRefAtoms(HTMLAtoms_info, + MOZ_ARRAY_LENGTH(HTMLAtoms_info)); } } @@ -59,10 +63,8 @@ void nsHTMLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define HTML_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsHTMLAtomList.h" -#undef HTML_ATOM + nsAtomListUtils::ReleaseAtoms(HTMLAtoms_info, + MOZ_ARRAY_LENGTH(HTMLAtoms_info)); } } diff --git a/mozilla/content/shared/public/MANIFEST b/mozilla/content/shared/public/MANIFEST index 229f9be7ca9..6aa0e477a95 100644 --- a/mozilla/content/shared/public/MANIFEST +++ b/mozilla/content/shared/public/MANIFEST @@ -1,6 +1,7 @@ # # This is a list of local files which get copied to the mozilla:dist:content directory # +nsAtomListUtils.h nsBidiUtils.h nsChangeHint.h nsCSSAnonBoxList.h diff --git a/mozilla/content/shared/public/Makefile.in b/mozilla/content/shared/public/Makefile.in index 8f1924fd5ea..ce1954fcd8e 100644 --- a/mozilla/content/shared/public/Makefile.in +++ b/mozilla/content/shared/public/Makefile.in @@ -29,6 +29,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = content EXPORTS = \ +nsAtomListUtils.h \ nsBidiUtils.h \ nsChangeHint.h \ nsCSSAnonBoxList.h \ diff --git a/mozilla/content/shared/public/nsAtomListUtils.h b/mozilla/content/shared/public/nsAtomListUtils.h new file mode 100644 index 00000000000..4bee33a7ad2 --- /dev/null +++ b/mozilla/content/shared/public/nsAtomListUtils.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Original Code is nsAtomListUtils.h . + * + * The Initial Developer of the Original Code is L. David Baron. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * L. David Baron (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsAtomListUtils_h__ +#define nsAtomListUtils_h__ + +#include "prtypes.h" + +class nsIAtom; + +#define MOZ_ARRAY_LENGTH(a_) (sizeof(a_)/sizeof(a_[0])) + +struct nsAtomListInfo { + nsIAtom** mAtom; + const char* mString; +}; + +class nsAtomListUtils { +public: + static void AddRefAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount); + static void ReleaseAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount); + + static PRBool IsMember(nsIAtom *aAtom, + const nsAtomListInfo* aInfo, + PRUint32 aInfoCount); +}; + +#endif /* !defined(nsAtomListUtils_h__) */ diff --git a/mozilla/content/shared/src/Makefile.in b/mozilla/content/shared/src/Makefile.in index 2203ec2541f..6cc8b8fcad1 100644 --- a/mozilla/content/shared/src/Makefile.in +++ b/mozilla/content/shared/src/Makefile.in @@ -43,6 +43,7 @@ REQUIRES = xpcom \ $(NULL) CPPSRCS = \ + nsAtomListUtils.cpp \ nsCSSAnonBoxes.cpp \ nsCSSPseudoClasses.cpp \ nsCSSPseudoElements.cpp \ diff --git a/mozilla/content/shared/src/nsAtomListUtils.cpp b/mozilla/content/shared/src/nsAtomListUtils.cpp new file mode 100644 index 00000000000..ab8b161f74e --- /dev/null +++ b/mozilla/content/shared/src/nsAtomListUtils.cpp @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Original Code is nsAtomListUtils.h . + * + * The Initial Developer of the Original Code is L. David Baron. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * L. David Baron (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsAtomListUtils.h" +#include "nsIAtom.h" + +/* static */ void +nsAtomListUtils::AddRefAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aCount; + info != info_end; ++info) { + *(info->mAtom) = NS_NewPermanentAtom(info->mString); + } +} + +/* static */ void +nsAtomListUtils::ReleaseAtoms(const nsAtomListInfo* aInfo, PRUint32 aCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aCount; + info != info_end; ++info) { + NS_RELEASE(*(info->mAtom)); + } +} + +/* static */ PRBool +nsAtomListUtils::IsMember(nsIAtom *aAtom, + const nsAtomListInfo* aInfo, + PRUint32 aInfoCount) +{ + for (nsAtomListInfo *info = aInfo, *info_end = aInfo + aInfoCount; + info != info_end; ++info) { + if (aAtom == *(info->mAtom)) + return PR_TRUE; + } + return PR_FALSE; +} diff --git a/mozilla/content/shared/src/nsCSSAnonBoxes.cpp b/mozilla/content/shared/src/nsCSSAnonBoxes.cpp index 34c712fd6e4..f343a7997be 100644 --- a/mozilla/content/shared/src/nsCSSAnonBoxes.cpp +++ b/mozilla/content/shared/src/nsCSSAnonBoxes.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSAnonBoxes.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_ANON_BOX(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSAnonBoxes_info[] = { +#define CSS_ANON_BOX(name_, value_) \ + { (nsIAtom**)&nsCSSAnonBoxes::name_, value_ }, +#include "nsCSSAnonBoxList.h" +#undef CSS_ANON_BOX +}; + void nsCSSAnonBoxes::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_ANON_BOX(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSAnonBoxPseudo*, NS_NewPermanentAtom(_value)); -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX + nsAtomListUtils::AddRefAtoms(CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } } @@ -60,19 +65,14 @@ void nsCSSAnonBoxes::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_ANON_BOX(_name, _value) NS_RELEASE(_name); -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX + nsAtomListUtils::ReleaseAtoms(CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } } PRBool nsCSSAnonBoxes::IsAnonBox(nsIAtom *aAtom) { - return -#define CSS_ANON_BOX(_name, _value) (aAtom == _name) || -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } diff --git a/mozilla/content/shared/src/nsCSSPseudoClasses.cpp b/mozilla/content/shared/src/nsCSSPseudoClasses.cpp index f4383898f18..4cfa48aa096 100644 --- a/mozilla/content/shared/src/nsCSSPseudoClasses.cpp +++ b/mozilla/content/shared/src/nsCSSPseudoClasses.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSPseudoClasses.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_PSEUDO_CLASS(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSPseudoClasses_info[] = { +#define CSS_PSEUDO_CLASS(name_, value_) \ + { (nsIAtom**)&nsCSSPseudoClasses::name_, value_ }, +#include "nsCSSPseudoClassList.h" +#undef CSS_PSEUDO_CLASS +}; + void nsCSSPseudoClasses::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_PSEUDO_CLASS(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSPseudoClass*, NS_NewPermanentAtom(_value)); -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS + nsAtomListUtils::AddRefAtoms(CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } } @@ -60,19 +65,14 @@ void nsCSSPseudoClasses::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_PSEUDO_CLASS(_name, _value) NS_RELEASE(_name); -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS + nsAtomListUtils::ReleaseAtoms(CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } } PRBool nsCSSPseudoClasses::IsPseudoClass(nsIAtom *aAtom) { - return -#define CSS_PSEUDO_CLASS(_name, _value) (aAtom == _name) || -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } diff --git a/mozilla/content/shared/src/nsCSSPseudoElements.cpp b/mozilla/content/shared/src/nsCSSPseudoElements.cpp index 7cc81151860..8a0b7573af1 100644 --- a/mozilla/content/shared/src/nsCSSPseudoElements.cpp +++ b/mozilla/content/shared/src/nsCSSPseudoElements.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSPseudoElements.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_PSEUDO_ELEMENT(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSPseudoElements_info[] = { +#define CSS_PSEUDO_ELEMENT(name_, value_) \ + { (nsIAtom**)&nsCSSPseudoElements::name_, value_ }, +#include "nsCSSPseudoElementList.h" +#undef CSS_PSEUDO_ELEMENT +}; + void nsCSSPseudoElements::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_PSEUDO_ELEMENT(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSPseudoElement*, NS_NewPermanentAtom(_value)); -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT + nsAtomListUtils::AddRefAtoms(CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); } } @@ -60,19 +65,14 @@ void nsCSSPseudoElements::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_PSEUDO_ELEMENT(_name, _value) NS_RELEASE(_name); -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT + nsAtomListUtils::ReleaseAtoms(CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); } } PRBool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) { - return -#define CSS_PSEUDO_ELEMENT(_name, _value) (aAtom == _name) || -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); } diff --git a/mozilla/content/shared/src/nsHTMLAtoms.cpp b/mozilla/content/shared/src/nsHTMLAtoms.cpp index 0fd9bb7c0cd..b526e18123b 100644 --- a/mozilla/content/shared/src/nsHTMLAtoms.cpp +++ b/mozilla/content/shared/src/nsHTMLAtoms.cpp @@ -36,22 +36,26 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsHTMLAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define HTML_ATOM(_name, _value) nsIAtom* nsHTMLAtoms::_name; #include "nsHTMLAtomList.h" #undef HTML_ATOM - static nsrefcnt gRefCnt; +static const nsAtomListInfo HTMLAtoms_info[] = { +#define HTML_ATOM(name_, value_) { &nsHTMLAtoms::name_, value_ }, +#include "nsHTMLAtomList.h" +#undef HTML_ATOM +}; + void nsHTMLAtoms::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define HTML_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsHTMLAtomList.h" -#undef HTML_ATOM + nsAtomListUtils::AddRefAtoms(HTMLAtoms_info, + MOZ_ARRAY_LENGTH(HTMLAtoms_info)); } } @@ -59,10 +63,8 @@ void nsHTMLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define HTML_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsHTMLAtomList.h" -#undef HTML_ATOM + nsAtomListUtils::ReleaseAtoms(HTMLAtoms_info, + MOZ_ARRAY_LENGTH(HTMLAtoms_info)); } } diff --git a/mozilla/content/shared/src/nsLayoutAtoms.cpp b/mozilla/content/shared/src/nsLayoutAtoms.cpp index 0f130c46da7..d4a961a2430 100644 --- a/mozilla/content/shared/src/nsLayoutAtoms.cpp +++ b/mozilla/content/shared/src/nsLayoutAtoms.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsLayoutAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define LAYOUT_ATOM(_name, _value) nsIAtom* nsLayoutAtoms::_name; @@ -45,13 +46,17 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo LayoutAtoms_info[] = { +#define LAYOUT_ATOM(name_, value_) { &nsLayoutAtoms::name_, value_ }, +#include "nsLayoutAtomList.h" +#undef LAYOUT_ATOM +}; + void nsLayoutAtoms::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define LAYOUT_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsLayoutAtomList.h" -#undef LAYOUT_ATOM + nsAtomListUtils::AddRefAtoms(LayoutAtoms_info, + MOZ_ARRAY_LENGTH(LayoutAtoms_info)); } } @@ -59,10 +64,8 @@ void nsLayoutAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define LAYOUT_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsLayoutAtomList.h" -#undef LAYOUT_ATOM + nsAtomListUtils::ReleaseAtoms(LayoutAtoms_info, + MOZ_ARRAY_LENGTH(LayoutAtoms_info)); } } diff --git a/mozilla/content/shared/src/nsSVGAtoms.cpp b/mozilla/content/shared/src/nsSVGAtoms.cpp index b284d8ac183..21212f9fc03 100644 --- a/mozilla/content/shared/src/nsSVGAtoms.cpp +++ b/mozilla/content/shared/src/nsSVGAtoms.cpp @@ -23,6 +23,7 @@ */ #include "nsSVGAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define SVG_ATOM(_name, _value) nsIAtom* nsSVGAtoms::_name; @@ -31,13 +32,17 @@ static nsrefcnt gRefCnt = 0; +static const nsAtomListInfo SVGAtoms_info[] = { +#define SVG_ATOM(name_, value_) { &nsSVGAtoms::name_, value_ }, +#include "nsSVGAtomList.h" +#undef SVG_ATOM +}; + void nsSVGAtoms::AddRefAtoms() { if (gRefCnt == 0) { - // now register the atoms -#define SVG_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsSVGAtomList.h" -#undef SVG_ATOM + nsAtomListUtils::AddRefAtoms(SVGAtoms_info, + MOZ_ARRAY_LENGTH(SVGAtoms_info)); } ++gRefCnt; } @@ -46,8 +51,7 @@ void nsSVGAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of SVG atoms"); if (--gRefCnt == 0) { -#define SVG_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsSVGAtomList.h" -#undef SVG_ATOM + nsAtomListUtils::ReleaseAtoms(SVGAtoms_info, + MOZ_ARRAY_LENGTH(SVGAtoms_info)); } } diff --git a/mozilla/content/shared/src/nsXBLAtoms.cpp b/mozilla/content/shared/src/nsXBLAtoms.cpp index 94e468d8d4a..58f9ad095b9 100644 --- a/mozilla/content/shared/src/nsXBLAtoms.cpp +++ b/mozilla/content/shared/src/nsXBLAtoms.cpp @@ -37,9 +37,8 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsString.h" #include "nsXBLAtoms.h" -#include "nsContentCID.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define XBL_ATOM(_name, _value) nsIAtom* nsXBLAtoms::_name; @@ -49,13 +48,17 @@ static nsrefcnt gRefCnt = 0; +static const nsAtomListInfo XBLAtoms_info[] = { +#define XBL_ATOM(name_, value_) { &nsXBLAtoms::name_, value_ }, +#include "nsXBLAtomList.h" +#undef XBL_ATOM +}; + void nsXBLAtoms::AddRefAtoms() { if (gRefCnt == 0) { - // now register the atoms -#define XBL_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsXBLAtomList.h" -#undef XBL_ATOM + nsAtomListUtils::AddRefAtoms(XBLAtoms_info, + MOZ_ARRAY_LENGTH(XBLAtoms_info)); } ++gRefCnt; } @@ -64,8 +67,7 @@ void nsXBLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of XBL atoms"); if (--gRefCnt == 0) { -#define XBL_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsXBLAtomList.h" -#undef XBL_ATOM + nsAtomListUtils::ReleaseAtoms(XBLAtoms_info, + MOZ_ARRAY_LENGTH(XBLAtoms_info)); } } diff --git a/mozilla/content/shared/src/nsXULAtoms.cpp b/mozilla/content/shared/src/nsXULAtoms.cpp index e9499bf9dc6..73e43911fd5 100644 --- a/mozilla/content/shared/src/nsXULAtoms.cpp +++ b/mozilla/content/shared/src/nsXULAtoms.cpp @@ -37,8 +37,8 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsString.h" #include "nsXULAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define XUL_ATOM(_name, _value) nsIAtom* nsXULAtoms::_name; @@ -48,13 +48,17 @@ static nsrefcnt gRefCnt = 0; +static const nsAtomListInfo XULAtoms_info[] = { +#define XUL_ATOM(name_, value_) { &nsXULAtoms::name_, value_ }, +#include "nsXULAtomList.h" +#undef XUL_ATOM +}; + void nsXULAtoms::AddRefAtoms() { if (++gRefCnt == 1) { - // create atoms -#define XUL_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsXULAtomList.h" -#undef XUL_ATOM + nsAtomListUtils::AddRefAtoms(XULAtoms_info, + MOZ_ARRAY_LENGTH(XULAtoms_info)); } } @@ -62,9 +66,7 @@ void nsXULAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of xul atoms"); if (--gRefCnt == 0) { - // release atoms -#define XUL_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsXULAtomList.h" -#undef XUL_ATOM + nsAtomListUtils::ReleaseAtoms(XULAtoms_info, + MOZ_ARRAY_LENGTH(XULAtoms_info)); } } diff --git a/mozilla/content/svg/content/src/nsSVGAtoms.cpp b/mozilla/content/svg/content/src/nsSVGAtoms.cpp index b284d8ac183..21212f9fc03 100644 --- a/mozilla/content/svg/content/src/nsSVGAtoms.cpp +++ b/mozilla/content/svg/content/src/nsSVGAtoms.cpp @@ -23,6 +23,7 @@ */ #include "nsSVGAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define SVG_ATOM(_name, _value) nsIAtom* nsSVGAtoms::_name; @@ -31,13 +32,17 @@ static nsrefcnt gRefCnt = 0; +static const nsAtomListInfo SVGAtoms_info[] = { +#define SVG_ATOM(name_, value_) { &nsSVGAtoms::name_, value_ }, +#include "nsSVGAtomList.h" +#undef SVG_ATOM +}; + void nsSVGAtoms::AddRefAtoms() { if (gRefCnt == 0) { - // now register the atoms -#define SVG_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsSVGAtomList.h" -#undef SVG_ATOM + nsAtomListUtils::AddRefAtoms(SVGAtoms_info, + MOZ_ARRAY_LENGTH(SVGAtoms_info)); } ++gRefCnt; } @@ -46,8 +51,7 @@ void nsSVGAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of SVG atoms"); if (--gRefCnt == 0) { -#define SVG_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsSVGAtomList.h" -#undef SVG_ATOM + nsAtomListUtils::ReleaseAtoms(SVGAtoms_info, + MOZ_ARRAY_LENGTH(SVGAtoms_info)); } } diff --git a/mozilla/content/xbl/src/nsXBLAtoms.cpp b/mozilla/content/xbl/src/nsXBLAtoms.cpp index 94e468d8d4a..58f9ad095b9 100644 --- a/mozilla/content/xbl/src/nsXBLAtoms.cpp +++ b/mozilla/content/xbl/src/nsXBLAtoms.cpp @@ -37,9 +37,8 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsString.h" #include "nsXBLAtoms.h" -#include "nsContentCID.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define XBL_ATOM(_name, _value) nsIAtom* nsXBLAtoms::_name; @@ -49,13 +48,17 @@ static nsrefcnt gRefCnt = 0; +static const nsAtomListInfo XBLAtoms_info[] = { +#define XBL_ATOM(name_, value_) { &nsXBLAtoms::name_, value_ }, +#include "nsXBLAtomList.h" +#undef XBL_ATOM +}; + void nsXBLAtoms::AddRefAtoms() { if (gRefCnt == 0) { - // now register the atoms -#define XBL_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsXBLAtomList.h" -#undef XBL_ATOM + nsAtomListUtils::AddRefAtoms(XBLAtoms_info, + MOZ_ARRAY_LENGTH(XBLAtoms_info)); } ++gRefCnt; } @@ -64,8 +67,7 @@ void nsXBLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of XBL atoms"); if (--gRefCnt == 0) { -#define XBL_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsXBLAtomList.h" -#undef XBL_ATOM + nsAtomListUtils::ReleaseAtoms(XBLAtoms_info, + MOZ_ARRAY_LENGTH(XBLAtoms_info)); } } diff --git a/mozilla/layout/base/nsLayoutAtoms.cpp b/mozilla/layout/base/nsLayoutAtoms.cpp index 0f130c46da7..d4a961a2430 100644 --- a/mozilla/layout/base/nsLayoutAtoms.cpp +++ b/mozilla/layout/base/nsLayoutAtoms.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsLayoutAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define LAYOUT_ATOM(_name, _value) nsIAtom* nsLayoutAtoms::_name; @@ -45,13 +46,17 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo LayoutAtoms_info[] = { +#define LAYOUT_ATOM(name_, value_) { &nsLayoutAtoms::name_, value_ }, +#include "nsLayoutAtomList.h" +#undef LAYOUT_ATOM +}; + void nsLayoutAtoms::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define LAYOUT_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); -#include "nsLayoutAtomList.h" -#undef LAYOUT_ATOM + nsAtomListUtils::AddRefAtoms(LayoutAtoms_info, + MOZ_ARRAY_LENGTH(LayoutAtoms_info)); } } @@ -59,10 +64,8 @@ void nsLayoutAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define LAYOUT_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsLayoutAtomList.h" -#undef LAYOUT_ATOM + nsAtomListUtils::ReleaseAtoms(LayoutAtoms_info, + MOZ_ARRAY_LENGTH(LayoutAtoms_info)); } } diff --git a/mozilla/layout/mathml/content/src/Makefile.in b/mozilla/layout/mathml/content/src/Makefile.in index fa2cfb9c76e..edbb8a7b40d 100644 --- a/mozilla/layout/mathml/content/src/Makefile.in +++ b/mozilla/layout/mathml/content/src/Makefile.in @@ -34,6 +34,7 @@ REQUIRES = xpcom \ string \ necko \ gfx \ + content \ $(NULL) include $(topsrcdir)/config/config.mk diff --git a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp index 71933a7eae5..24150b50552 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp +++ b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp @@ -20,6 +20,7 @@ */ #include "nsMathMLAtoms.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define MATHML_ATOM(_name, _value) nsIAtom* nsMathMLAtoms::_name; @@ -29,12 +30,16 @@ static nsrefcnt gRefCnt = 0; -void nsMathMLAtoms::AddRefAtoms() { - if (gRefCnt == 0) { - // create atoms -#define MATHML_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); +static const nsAtomListInfo MathMLAtoms_info[] = { +#define MATHML_ATOM(name_, value_) { &nsMathMLAtoms::name_, value_ }, #include "nsMathMLAtomList.h" #undef MATHML_ATOM +}; + +void nsMathMLAtoms::AddRefAtoms() { + if (gRefCnt == 0) { + nsAtomListUtils::AddRefAtoms(MathMLAtoms_info, + MOZ_ARRAY_LENGTH(MathMLAtoms_info)); } ++gRefCnt; } @@ -42,9 +47,7 @@ void nsMathMLAtoms::AddRefAtoms() { void nsMathMLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of MathML atoms"); if (--gRefCnt == 0) { - // release atoms -#define MATHML_ATOM(_name, _value) NS_RELEASE(_name); -#include "nsMathMLAtomList.h" -#undef MATHML_ATOM + nsAtomListUtils::ReleaseAtoms(MathMLAtoms_info, + MOZ_ARRAY_LENGTH(MathMLAtoms_info)); } } diff --git a/mozilla/layout/style/nsCSSAnonBoxes.cpp b/mozilla/layout/style/nsCSSAnonBoxes.cpp index 34c712fd6e4..f343a7997be 100644 --- a/mozilla/layout/style/nsCSSAnonBoxes.cpp +++ b/mozilla/layout/style/nsCSSAnonBoxes.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSAnonBoxes.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_ANON_BOX(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSAnonBoxes_info[] = { +#define CSS_ANON_BOX(name_, value_) \ + { (nsIAtom**)&nsCSSAnonBoxes::name_, value_ }, +#include "nsCSSAnonBoxList.h" +#undef CSS_ANON_BOX +}; + void nsCSSAnonBoxes::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_ANON_BOX(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSAnonBoxPseudo*, NS_NewPermanentAtom(_value)); -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX + nsAtomListUtils::AddRefAtoms(CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } } @@ -60,19 +65,14 @@ void nsCSSAnonBoxes::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_ANON_BOX(_name, _value) NS_RELEASE(_name); -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX + nsAtomListUtils::ReleaseAtoms(CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } } PRBool nsCSSAnonBoxes::IsAnonBox(nsIAtom *aAtom) { - return -#define CSS_ANON_BOX(_name, _value) (aAtom == _name) || -#include "nsCSSAnonBoxList.h" -#undef CSS_ANON_BOX - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSAnonBoxes_info, + MOZ_ARRAY_LENGTH(CSSAnonBoxes_info)); } diff --git a/mozilla/layout/style/nsCSSPseudoClasses.cpp b/mozilla/layout/style/nsCSSPseudoClasses.cpp index f4383898f18..4cfa48aa096 100644 --- a/mozilla/layout/style/nsCSSPseudoClasses.cpp +++ b/mozilla/layout/style/nsCSSPseudoClasses.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSPseudoClasses.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_PSEUDO_CLASS(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSPseudoClasses_info[] = { +#define CSS_PSEUDO_CLASS(name_, value_) \ + { (nsIAtom**)&nsCSSPseudoClasses::name_, value_ }, +#include "nsCSSPseudoClassList.h" +#undef CSS_PSEUDO_CLASS +}; + void nsCSSPseudoClasses::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_PSEUDO_CLASS(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSPseudoClass*, NS_NewPermanentAtom(_value)); -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS + nsAtomListUtils::AddRefAtoms(CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } } @@ -60,19 +65,14 @@ void nsCSSPseudoClasses::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_PSEUDO_CLASS(_name, _value) NS_RELEASE(_name); -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS + nsAtomListUtils::ReleaseAtoms(CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } } PRBool nsCSSPseudoClasses::IsPseudoClass(nsIAtom *aAtom) { - return -#define CSS_PSEUDO_CLASS(_name, _value) (aAtom == _name) || -#include "nsCSSPseudoClassList.h" -#undef CSS_PSEUDO_CLASS - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSPseudoClasses_info, + MOZ_ARRAY_LENGTH(CSSPseudoClasses_info)); } diff --git a/mozilla/layout/style/nsCSSPseudoElements.cpp b/mozilla/layout/style/nsCSSPseudoElements.cpp index 7cc81151860..8a0b7573af1 100644 --- a/mozilla/layout/style/nsCSSPseudoElements.cpp +++ b/mozilla/layout/style/nsCSSPseudoElements.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCSSPseudoElements.h" +#include "nsAtomListUtils.h" // define storage for all atoms #define CSS_PSEUDO_ELEMENT(_name, _value) \ @@ -45,14 +46,18 @@ static nsrefcnt gRefCnt; +static const nsAtomListInfo CSSPseudoElements_info[] = { +#define CSS_PSEUDO_ELEMENT(name_, value_) \ + { (nsIAtom**)&nsCSSPseudoElements::name_, value_ }, +#include "nsCSSPseudoElementList.h" +#undef CSS_PSEUDO_ELEMENT +}; + void nsCSSPseudoElements::AddRefAtoms() { if (0 == gRefCnt++) { - // create atoms -#define CSS_PSEUDO_ELEMENT(_name, _value) \ - _name = NS_STATIC_CAST(nsICSSPseudoElement*, NS_NewPermanentAtom(_value)); -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT + nsAtomListUtils::AddRefAtoms(CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); } } @@ -60,19 +65,14 @@ void nsCSSPseudoElements::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release atoms"); if (--gRefCnt == 0) { - // release atoms -#define CSS_PSEUDO_ELEMENT(_name, _value) NS_RELEASE(_name); -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT + nsAtomListUtils::ReleaseAtoms(CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); } } PRBool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) { - return -#define CSS_PSEUDO_ELEMENT(_name, _value) (aAtom == _name) || -#include "nsCSSPseudoElementList.h" -#undef CSS_PSEUDO_ELEMENT - PR_FALSE; + return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info, + MOZ_ARRAY_LENGTH(CSSPseudoElements_info)); }