Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /* atom list for CSS anonymous boxes */
7 :
8 : #include "mozilla/ArrayUtils.h"
9 :
10 : #include "nsCSSAnonBoxes.h"
11 : #include "nsAtomListUtils.h"
12 : #include "nsStaticAtom.h"
13 :
14 : using namespace mozilla;
15 :
16 : // define storage for all atoms
17 : #define CSS_ANON_BOX(name_, value_, skips_fixup_) \
18 : nsICSSAnonBoxPseudo* nsCSSAnonBoxes::name_;
19 : #include "nsCSSAnonBoxList.h"
20 : #undef CSS_ANON_BOX
21 :
22 : #define CSS_ANON_BOX(name_, value_, skips_fixup_) \
23 : NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
24 : #include "nsCSSAnonBoxList.h"
25 : #undef CSS_ANON_BOX
26 :
27 : static const nsStaticAtom CSSAnonBoxes_info[] = {
28 : // Put the non-inheriting anon boxes first, so we can index into them easily.
29 : #define CSS_ANON_BOX(name_, value_, skips_fixup_) /* nothing */
30 : #define CSS_NON_INHERITING_ANON_BOX(name_, value_) \
31 : NS_STATIC_ATOM(name_##_buffer, (nsIAtom**)&nsCSSAnonBoxes::name_),
32 : #include "nsCSSAnonBoxList.h"
33 : #undef CSS_NON_INHERITING_ANON_BOX
34 : #undef CSS_ANON_BOX
35 :
36 : #define CSS_ANON_BOX(name_, value_, skips_fixup_) \
37 : NS_STATIC_ATOM(name_##_buffer, (nsIAtom**)&nsCSSAnonBoxes::name_),
38 : #define CSS_NON_INHERITING_ANON_BOX(name_, value_) /* nothing */
39 : #include "nsCSSAnonBoxList.h"
40 : #undef CSS_NON_INHERITING_ANON_BOX
41 : #undef CSS_ANON_BOX
42 : };
43 :
44 3 : void nsCSSAnonBoxes::AddRefAtoms()
45 : {
46 3 : NS_RegisterStaticAtoms(CSSAnonBoxes_info);
47 3 : }
48 :
49 5299 : bool nsCSSAnonBoxes::IsAnonBox(nsIAtom *aAtom)
50 : {
51 5299 : return nsAtomListUtils::IsMember(aAtom, CSSAnonBoxes_info,
52 10598 : ArrayLength(CSSAnonBoxes_info));
53 : }
54 :
55 : #ifdef MOZ_XUL
56 : /* static */ bool
57 824 : nsCSSAnonBoxes::IsTreePseudoElement(nsIAtom* aPseudo)
58 : {
59 824 : MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudo));
60 1648 : return StringBeginsWith(nsDependentAtomString(aPseudo),
61 2472 : NS_LITERAL_STRING(":-moz-tree-"));
62 : }
63 : #endif
64 :
65 : /* static*/ nsCSSAnonBoxes::NonInheriting
66 0 : nsCSSAnonBoxes::NonInheritingTypeForPseudoTag(nsIAtom* aPseudo)
67 : {
68 0 : MOZ_ASSERT(IsNonInheritingAnonBox(aPseudo));
69 0 : for (NonInheritingBase i = 0;
70 0 : i < ArrayLength(CSSAnonBoxes_info);
71 : ++i) {
72 0 : if (*CSSAnonBoxes_info[i].mAtom == aPseudo) {
73 0 : return static_cast<NonInheriting>(i);
74 : }
75 : }
76 :
77 0 : MOZ_CRASH("Bogus pseudo passed to NonInheritingTypeForPseudoTag");
78 : }
79 :
80 : /* static */ nsIAtom*
81 0 : nsCSSAnonBoxes::GetNonInheritingPseudoAtom(NonInheriting aBoxType)
82 : {
83 0 : MOZ_ASSERT(aBoxType < NonInheriting::_Count);
84 0 : return *CSSAnonBoxes_info[static_cast<NonInheritingBase>(aBoxType)].mAtom;
85 : }
|