nsCOMPtr<nsIHTMLContent> node;
nsCOMPtr<nsIContent> content;
nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext,                                   nsEvent* aEvent,                                   nsIDOMEvent** aDOMEvent,                                   PRUint32 aFlags,                                   nsEventStatus* aEventStatus){  NS_ENSURE_ARG_POINTER(aEventStatus);  nsresult rv;  rv = nsGenericHTMLContainerFormElement::HandleDOMEvent(aPresContext,                                                         aEvent,                                                         aDOMEvent,                                                         aFlags,                                                         aEventStatus);  // Now a little special trickery because we are a label:  // We need to pass this event on to our child iff it is a focus,  // keypress/up/dn, mouseclick/dblclick/up/down.  if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT & aFlags) &&      ((nsEventStatus_eIgnore == *aEventStatus) ||       (nsEventStatus_eConsumeNoDefault == *aEventStatus)) ) {    PRBool isFormElement = PR_FALSE;    nsCOMPtr<nsIHTMLContent> node; // Node we are a label for    switch (aEvent->message) {      case NS_FOCUS_CONTENT:// Bug 49897: According to the spec, the following should not be passed// Bug 7554: Despite the spec, IE passes left click events, so for// compatability:      case NS_MOUSE_LEFT_CLICK://      case NS_MOUSE_LEFT_DOUBLECLICK://      case NS_MOUSE_LEFT_BUTTON_UP://      case NS_MOUSE_LEFT_BUTTON_DOWN://      case NS_MOUSE_MIDDLE_CLICK://      case NS_MOUSE_MIDDLE_DOUBLECLICK://      case NS_MOUSE_MIDDLE_BUTTON_UP://      case NS_MOUSE_MIDDLE_BUTTON_DOWN://      case NS_MOUSE_RIGHT_CLICK://      case NS_MOUSE_RIGHT_DOUBLECLICK://      case NS_MOUSE_RIGHT_BUTTON_UP://      case NS_MOUSE_RIGHT_BUTTON_DOWN://      case NS_KEY_PRESS://      case NS_KEY_UP://      case NS_KEY_DOWN:      {        // Get the element that this label is for        nsAutoString elementId;        rv = GetHtmlFor(elementId);        if (NS_SUCCEEDED(rv) && elementId.Length()) { // --- We have a FOR attr          nsCOMPtr<nsIDocument> iDoc;          rv = GetDocument(*getter_AddRefs(iDoc));          if (NS_SUCCEEDED(rv)) {            nsCOMPtr<nsIDOMElement> domElement;            nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(iDoc));            if (domDoc) {              rv = domDoc->GetElementById(elementId,                                          getter_AddRefs(domElement));            }            if (NS_SUCCEEDED(rv) && domElement) {              // Get our grubby paws on the content interface              node = do_QueryInterface(domElement, &rv);              // Find out of this is a form element.              if (NS_SUCCEEDED(rv)) {                nsIFormControlFrame* control;                GetPrimaryFrame(node, control, PR_TRUE, PR_FALSE);                isFormElement = control != nsnull;              }            }          }        } else {          // --- No FOR attribute, we are a label for our first child          // element          PRInt32 numNodes;          rv = ChildCount(numNodes);          if (NS_SUCCEEDED(rv)) {            nsCOMPtr<nsIContent> contNode;            PRInt32 i;            for (i = 0; NS_SUCCEEDED(rv) && !isFormElement && (i < numNodes);                 i++) {              rv = ChildAt(i, *getter_AddRefs(contNode));              if (NS_SUCCEEDED(rv) && contNode) {                // We need to make sure this child is a form element                nsresult isHTMLContent = PR_FALSE;                node = do_QueryInterface(contNode, &isHTMLContent);                if (NS_SUCCEEDED(isHTMLContent) && node) {                  // Find out of this is a form element.                  nsIFormControlFrame* control;                  GetPrimaryFrame(node, control, PR_TRUE, PR_FALSE);                  isFormElement = control != nsnull;                }              }            }          }        }      } // Close should handle    } // Close switch    // If we found an element, pass along the event to it.    if (NS_SUCCEEDED(rv) && node) {      // Only pass along event if this is a form element      if (isFormElement) {        rv = node->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,                                  aEventStatus);      }    }  } // Close trickery  return rv;}