nsHtml5StackNode.cpp (7073B)
1 /* 2 * Copyright (c) 2007 Henri Sivonen 3 * Copyright (c) 2007-2011 Mozilla Foundation 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 /* 25 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT. 26 * Please edit StackNode.java instead and regenerate. 27 */ 28 29 #define nsHtml5StackNode_cpp__ 30 31 #include "nsHtml5AttributeName.h" 32 #include "nsHtml5ElementName.h" 33 #include "nsHtml5Tokenizer.h" 34 #include "nsHtml5TreeBuilder.h" 35 #include "nsHtml5UTF16Buffer.h" 36 #include "nsHtml5StateSnapshot.h" 37 #include "nsHtml5Portability.h" 38 39 #include "nsHtml5StackNode.h" 40 41 int32_t nsHtml5StackNode::getGroup() { 42 return flags & nsHtml5ElementName::GROUP_MASK; 43 } 44 45 bool nsHtml5StackNode::isScoping() { 46 return (flags & nsHtml5ElementName::SCOPING); 47 } 48 49 bool nsHtml5StackNode::isSpecial() { 50 return (flags & nsHtml5ElementName::SPECIAL); 51 } 52 53 bool nsHtml5StackNode::isFosterParenting() { 54 return (flags & nsHtml5ElementName::FOSTER_PARENTING); 55 } 56 57 bool nsHtml5StackNode::isHtmlIntegrationPoint() { 58 return (flags & nsHtml5ElementName::HTML_INTEGRATION_POINT); 59 } 60 61 nsHtml5StackNode::nsHtml5StackNode(int32_t idxInTreeBuilder) 62 : idxInTreeBuilder(idxInTreeBuilder), 63 flags(0), 64 name(nullptr), 65 popName(nullptr), 66 ns(0), 67 node(nullptr), 68 attributes(nullptr), 69 refcount(0), 70 htmlCreator(nullptr) { 71 MOZ_COUNT_CTOR(nsHtml5StackNode); 72 } 73 74 mozilla::dom::HTMLContentCreatorFunction nsHtml5StackNode::getHtmlCreator() { 75 return htmlCreator; 76 } 77 78 void nsHtml5StackNode::setValues( 79 int32_t flags, int32_t ns, nsAtom* name, nsIContentHandle* node, 80 nsAtom* popName, nsHtml5HtmlAttributes* attributes, 81 mozilla::dom::HTMLContentCreatorFunction htmlCreator) { 82 MOZ_ASSERT(isUnused()); 83 this->flags = flags; 84 this->name = name; 85 this->popName = popName; 86 this->ns = ns; 87 this->node = node; 88 this->attributes = attributes; 89 this->refcount = 1; 90 this->htmlCreator = htmlCreator; 91 } 92 93 void nsHtml5StackNode::setValues(nsHtml5ElementName* elementName, 94 nsIContentHandle* node) { 95 MOZ_ASSERT(isUnused()); 96 this->flags = elementName->getFlags(); 97 this->name = elementName->getName(); 98 this->popName = elementName->getName(); 99 this->ns = kNameSpaceID_XHTML; 100 this->node = node; 101 this->attributes = nullptr; 102 this->refcount = 1; 103 MOZ_ASSERT(elementName->isInterned(), 104 "Don't use this constructor for custom elements."); 105 this->htmlCreator = nullptr; 106 } 107 108 void nsHtml5StackNode::setValues(nsHtml5ElementName* elementName, 109 nsIContentHandle* node, 110 nsHtml5HtmlAttributes* attributes) { 111 MOZ_ASSERT(isUnused()); 112 this->flags = elementName->getFlags(); 113 this->name = elementName->getName(); 114 this->popName = elementName->getName(); 115 this->ns = kNameSpaceID_XHTML; 116 this->node = node; 117 this->attributes = attributes; 118 this->refcount = 1; 119 MOZ_ASSERT(elementName->isInterned(), 120 "Don't use this constructor for custom elements."); 121 this->htmlCreator = elementName->getHtmlCreator(); 122 } 123 124 void nsHtml5StackNode::setValues(nsHtml5ElementName* elementName, 125 nsIContentHandle* node, nsAtom* popName) { 126 MOZ_ASSERT(isUnused()); 127 this->flags = elementName->getFlags(); 128 this->name = elementName->getName(); 129 this->popName = popName; 130 this->ns = kNameSpaceID_XHTML; 131 this->node = node; 132 this->attributes = nullptr; 133 this->refcount = 1; 134 this->htmlCreator = nullptr; 135 } 136 137 void nsHtml5StackNode::setValues(nsHtml5ElementName* elementName, 138 nsAtom* popName, nsIContentHandle* node) { 139 MOZ_ASSERT(isUnused()); 140 this->flags = prepareSvgFlags(elementName->getFlags()); 141 this->name = elementName->getName(); 142 this->popName = popName; 143 this->ns = kNameSpaceID_SVG; 144 this->node = node; 145 this->attributes = nullptr; 146 this->refcount = 1; 147 this->htmlCreator = nullptr; 148 } 149 150 void nsHtml5StackNode::setValues(nsHtml5ElementName* elementName, 151 nsIContentHandle* node, nsAtom* popName, 152 bool markAsIntegrationPoint) { 153 MOZ_ASSERT(isUnused()); 154 this->flags = 155 prepareMathFlags(elementName->getFlags(), markAsIntegrationPoint); 156 this->name = elementName->getName(); 157 this->popName = popName; 158 this->ns = kNameSpaceID_MathML; 159 this->node = node; 160 this->attributes = nullptr; 161 this->refcount = 1; 162 this->htmlCreator = nullptr; 163 } 164 165 int32_t nsHtml5StackNode::prepareSvgFlags(int32_t flags) { 166 flags &= 167 ~(nsHtml5ElementName::FOSTER_PARENTING | nsHtml5ElementName::SCOPING | 168 nsHtml5ElementName::SPECIAL | nsHtml5ElementName::OPTIONAL_END_TAG); 169 if ((flags & nsHtml5ElementName::SCOPING_AS_SVG)) { 170 flags |= (nsHtml5ElementName::SCOPING | nsHtml5ElementName::SPECIAL | 171 nsHtml5ElementName::HTML_INTEGRATION_POINT); 172 } 173 return flags; 174 } 175 176 int32_t nsHtml5StackNode::prepareMathFlags(int32_t flags, 177 bool markAsIntegrationPoint) { 178 flags &= 179 ~(nsHtml5ElementName::FOSTER_PARENTING | nsHtml5ElementName::SCOPING | 180 nsHtml5ElementName::SPECIAL | nsHtml5ElementName::OPTIONAL_END_TAG); 181 if ((flags & nsHtml5ElementName::SCOPING_AS_MATHML)) { 182 flags |= (nsHtml5ElementName::SCOPING | nsHtml5ElementName::SPECIAL); 183 } 184 if (markAsIntegrationPoint) { 185 flags |= nsHtml5ElementName::HTML_INTEGRATION_POINT; 186 } 187 return flags; 188 } 189 190 nsHtml5StackNode::~nsHtml5StackNode() { MOZ_COUNT_DTOR(nsHtml5StackNode); } 191 192 void nsHtml5StackNode::dropAttributes() { attributes = nullptr; } 193 194 void nsHtml5StackNode::retain() { refcount++; } 195 196 void nsHtml5StackNode::release(nsHtml5TreeBuilder* owningTreeBuilder) { 197 refcount--; 198 MOZ_ASSERT(refcount >= 0); 199 if (!refcount) { 200 delete attributes; 201 if (idxInTreeBuilder >= 0) { 202 owningTreeBuilder->notifyUnusedStackNode(idxInTreeBuilder); 203 } else { 204 MOZ_ASSERT(!owningTreeBuilder); 205 delete this; 206 } 207 } 208 } 209 210 bool nsHtml5StackNode::isUnused() { return !refcount; } 211 212 void nsHtml5StackNode::initializeStatics() {} 213 214 void nsHtml5StackNode::releaseStatics() {}