Logo Search packages:      
Sourcecode: xulrunner version File versions

nsresult nsGenericElement::UnsetAttr ( PRInt32  aNameSpaceID,
nsIAtom *  aAttr,
PRBool  aNotify 
) [virtual]

Remove an attribute so that it is no longer explicitly specified.

Parameters:
aNameSpaceID the namespace id of the attribute
aAttr the name of the attribute to unset
aNotify specifies whether or not the document should be notified of the attribute change

Implements nsIContent.

Reimplemented in nsGenericHTMLElement, nsGenericHTMLFormElement, nsHTMLOptGroupElement, and nsHTMLOptionElement.

Definition at line 4023 of file nsGenericElement.cpp.

References nsIContent::GetCurrentDoc(), HandleDOMEvent(), HasMutationListeners(), nsDOMSlots::mAttributeMap, and mAttrsAndChildren.

Referenced by nsGenericHTMLElement::UnsetAttr().

{
  NS_ASSERTION(nsnull != aName, "must have attribute name");

  PRInt32 index = mAttrsAndChildren.IndexOfAttr(aName, aNameSpaceID);
  if (index < 0) {
    return NS_OK;
  }

  nsIDocument *document = GetCurrentDoc();    
  mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);

  PRBool hasMutationListeners = document &&
    HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED);
  // Grab the attr node if needed before we remove it from the attr map
  nsCOMPtr<nsIDOMAttr> attrNode;
  
  if (document) {
    if (kNameSpaceID_XLink == aNameSpaceID && nsHTMLAtoms::href == aName) {
      // XLink URI might be changing.
      document->ForgetLink(this);
    }

    if (aNotify) {
      document->AttributeWillChange(this, aNameSpaceID, aName);
    }

    if (hasMutationListeners) {
      nsAutoString attrName;
      aName->ToString(attrName);
      GetAttributeNode(attrName, getter_AddRefs(attrNode));
    }
  }

  // Clear binding to nsIDOMNamedNodeMap
  nsDOMSlots *slots = GetExistingDOMSlots();
  if (slots && slots->mAttributeMap) {
    slots->mAttributeMap->DropAttribute(aNameSpaceID, aName);
  }

  nsAttrValue oldValue;
  nsresult rv = mAttrsAndChildren.RemoveAttrAt(index, oldValue);
  NS_ENSURE_SUCCESS(rv, rv);

  if (document) {
    nsXBLBinding *binding = document->BindingManager()->GetBinding(this);
    if (binding)
      binding->AttributeChanged(aName, aNameSpaceID, PR_TRUE, aNotify);

    if (aNotify) {
      document->AttributeChanged(this, aNameSpaceID, aName,
                                 nsIDOMMutationEvent::REMOVAL);
    }

    if (hasMutationListeners) {
      nsCOMPtr<nsIDOMEventTarget> node =
        do_QueryInterface(NS_STATIC_CAST(nsIContent *, this));
      nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node);

      mutation.mRelatedNode = attrNode;
      mutation.mAttrName = aName;

      nsAutoString value;
      oldValue.ToString(value);
      if (!value.IsEmpty())
        mutation.mPrevAttrValue = do_GetAtom(value);
      mutation.mAttrChange = nsIDOMMutationEvent::REMOVAL;

      nsEventStatus status = nsEventStatus_eIgnore;
      HandleDOMEvent(nsnull, &mutation, nsnull,
                     NS_EVENT_FLAG_INIT, &status);
    }
  }

  return NS_OK;
}


Generated by  Doxygen 1.6.0   Back to index