Bug 1331322 - Move MAY_HAVE_CLASS to mBoolFlags. r=bz draft
authorBobby Holley <bobbyholley@gmail.com>
Fri, 20 Jan 2017 18:24:41 -0800
changeset 485063 c8b2bd32c3a8009782a54068d2f59aee7a87ffbe
parent 485062 bd871fd18e9c09bd6143d1e895413074b4448426
child 485064 bc5a4ef8416f7fa6c9067bad1485bf025c268d5d
push id45616
push userbmo:bobbyholley@gmail.com
push dateThu, 16 Feb 2017 01:57:04 +0000
reviewersbz
bugs1331322
milestone54.0a1
Bug 1331322 - Move MAY_HAVE_CLASS to mBoolFlags. r=bz This fits a bit better with the other stuff, and allows us to add our new NAC bit with the other NAC related bits, which also happens to be a field that Servo already has easy access to.
dom/base/Element.cpp
dom/base/Element.h
dom/base/nsINode.h
dom/svg/nsSVGClass.cpp
dom/xul/nsXULElement.cpp
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -161,18 +161,17 @@ nsIContent::DoGetID() const
   MOZ_ASSERT(IsElement(), "Only elements can have IDs");
 
   return AsElement()->GetParsedAttr(nsGkAtoms::id)->GetAtomValue();
 }
 
 const nsAttrValue*
 Element::DoGetClasses() const
 {
-  MOZ_ASSERT(HasFlag(NODE_MAY_HAVE_CLASS), "Unexpected call");
-
+  MOZ_ASSERT(MayHaveClass(), "Unexpected call");
   if (IsSVGElement()) {
     const nsAttrValue* animClass =
       static_cast<const nsSVGElement*>(this)->GetAnimatedClassName();
     if (animClass) {
       return animClass;
     }
   }
 
@@ -2544,17 +2543,17 @@ Element::BeforeSetAttr(int32_t aNamespac
 bool
 Element::ParseAttribute(int32_t aNamespaceID,
                         nsIAtom* aAttribute,
                         const nsAString& aValue,
                         nsAttrValue& aResult)
 {
   if (aNamespaceID == kNameSpaceID_None) {
     if (aAttribute == nsGkAtoms::_class) {
-      SetFlags(NODE_MAY_HAVE_CLASS);
+      SetMayHaveClass();
       // Result should have been preparsed above.
       return true;
     }
     if (aAttribute == nsGkAtoms::id) {
       // Store id as an atom.  id="" means that the element has no id,
       // not that it has an emptystring as the id.
       RemoveFromIdTable();
       if (aValue.IsEmpty()) {
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -618,17 +618,17 @@ public:
   virtual bool IsNodeOfType(uint32_t aFlags) const override;
 
   /**
    * Get the class list of this element (this corresponds to the value of the
    * class attribute).  This may be null if there are no classes, but that's not
    * guaranteed (e.g. we could have class="").
    */
   const nsAttrValue* GetClasses() const {
-    if (HasFlag(NODE_MAY_HAVE_CLASS)) {
+    if (MayHaveClass()) {
       return DoGetClasses();
     }
     return nullptr;
   }
 
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override
   {
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -122,19 +122,18 @@ enum {
   // in the document and therefore should get bindings attached.
   NODE_FORCE_XBL_BINDINGS =               NODE_FLAG_BIT(5),
 
   // Whether a binding manager may have a pointer to this
   NODE_MAY_BE_IN_BINDING_MNGR =           NODE_FLAG_BIT(6),
 
   NODE_IS_EDITABLE =                      NODE_FLAG_BIT(7),
 
-  // For all Element nodes, NODE_MAY_HAVE_CLASS is guaranteed to be set if the
-  // node in fact has a class, but may be set even if it doesn't.
-  NODE_MAY_HAVE_CLASS =                   NODE_FLAG_BIT(8),
+  // Bit that will soon be used for other things.
+  THIS_BIT_BELONGS_TO_BHOLLEY =           NODE_FLAG_BIT(8),
 
   // Whether the node participates in a shadow tree.
   NODE_IS_IN_SHADOW_TREE =                NODE_FLAG_BIT(9),
 
   // Node has an :empty or :-moz-only-whitespace selector
   NODE_HAS_EMPTY_SELECTOR =               NODE_FLAG_BIT(10),
 
   // A child of the node has a selector such that any insertion,
@@ -1492,16 +1491,18 @@ private:
     // Set if mParent is an nsIContent
     ParentIsContent,
     // Set if this node is an Element
     NodeIsElement,
     // Set if the element has a non-empty id attribute. This can in rare
     // cases lie for nsXMLElement, such as when the node has been moved between
     // documents with different id mappings.
     ElementHasID,
+    // Set if the element might have a class.
+    ElementMayHaveClass,
     // Set if the element might have inline style.
     ElementMayHaveStyle,
     // Set if the element has a name attribute set.
     ElementHasName,
     // Set if the element might have a contenteditable attribute set.
     ElementMayHaveContentEditableAttr,
     // Set if the node is the common ancestor of the start/end nodes of a Range
     // that is in a Selection.
@@ -1586,16 +1587,18 @@ private:
 
 public:
   bool HasRenderingObservers() const
     { return GetBoolFlag(NodeHasRenderingObservers); }
   void SetHasRenderingObservers(bool aValue)
     { SetBoolFlag(NodeHasRenderingObservers, aValue); }
   bool IsContent() const { return GetBoolFlag(NodeIsContent); }
   bool HasID() const { return GetBoolFlag(ElementHasID); }
+  bool MayHaveClass() const { return GetBoolFlag(ElementMayHaveClass); }
+  void SetMayHaveClass() { SetBoolFlag(ElementMayHaveClass); }
   bool MayHaveStyle() const { return GetBoolFlag(ElementMayHaveStyle); }
   bool HasName() const { return GetBoolFlag(ElementHasName); }
   bool MayHaveContentEditableAttr() const
     { return GetBoolFlag(ElementMayHaveContentEditableAttr); }
   bool IsCommonAncestorForRangeInSelection() const
     { return GetBoolFlag(NodeIsCommonAncestorForRangeInSelection); }
   void SetCommonAncestorForRangeInSelection()
     { SetBoolFlag(NodeIsCommonAncestorForRangeInSelection); }
--- a/dom/svg/nsSVGClass.cpp
+++ b/dom/svg/nsSVGClass.cpp
@@ -65,17 +65,17 @@ nsSVGClass::ToDOMAnimatedString(nsSVGEle
 
 void
 nsSVGClass::SetBaseValue(const nsAString& aValue,
                          nsSVGElement *aSVGElement,
                          bool aDoSetAttr)
 {
   NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
 
-  aSVGElement->SetFlags(NODE_MAY_HAVE_CLASS);
+  aSVGElement->SetMayHaveClass();
   if (aDoSetAttr) {
     aSVGElement->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue, true);
   }
   if (mAnimVal) {
     aSVGElement->AnimationNeedsResample();
   }
 }
 
@@ -101,17 +101,17 @@ nsSVGClass::SetAnimValue(const nsAString
 {
   if (mAnimVal && mAnimVal->Equals(aValue)) {
     return;
   }
   if (!mAnimVal) {
     mAnimVal = new nsString();
   }
   *mAnimVal = aValue;
-  aSVGElement->SetFlags(NODE_MAY_HAVE_CLASS);
+  aSVGElement->SetMayHaveClass();
   aSVGElement->DidAnimateClass();
 }
 
 void
 DOMAnimatedString::GetAnimVal(nsAString& aResult)
 {
   mSVGElement->FlushAnimations();
   mVal->GetAnimValue(aResult, mSVGElement);
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -226,17 +226,17 @@ nsXULElement::Create(nsXULPrototypeEleme
 {
     RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
     RefPtr<nsXULElement> element = new nsXULElement(ni.forget());
     if (element) {
         if (aPrototype->mHasIdAttribute) {
             element->SetHasID();
         }
         if (aPrototype->mHasClassAttribute) {
-            element->SetFlags(NODE_MAY_HAVE_CLASS);
+            element->SetMayHaveClass();
         }
         if (aPrototype->mHasStyleAttribute) {
             element->SetMayHaveStyle();
         }
 
         element->MakeHeavyweight(aPrototype);
         if (aIsScriptable) {
             // Check each attribute on the prototype to see if we need to do
@@ -400,17 +400,17 @@ nsXULElement::Clone(mozilla::dom::NodeIn
         }
         NS_ENSURE_SUCCESS(rv, rv);
         element->AddListenerFor(*originalName, true);
         if (originalName->Equals(nsGkAtoms::id) &&
             !originalValue->IsEmptyString()) {
             element->SetHasID();
         }
         if (originalName->Equals(nsGkAtoms::_class)) {
-            element->SetFlags(NODE_MAY_HAVE_CLASS);
+            element->SetMayHaveClass();
         }
         if (originalName->Equals(nsGkAtoms::style)) {
             element->SetMayHaveStyle();
         }
     }
 
     element.forget(aResult);
     return rv;