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:
nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext,                                   nsEvent* aEvent,                                   nsIDOMEvent** aDOMEvent,                                   PRUint32 aFlags,                                   nsEventStatus* aEventStatus){  NS_ENSURE_ARG_POINTER(aEventStatus);  nsresult rv = mInner.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:      case NS_KEY_PRESS:      case NS_KEY_UP:      case NS_KEY_DOWN:      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:      {        // 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 = mInner.GetDocument(*getter_AddRefs(iDoc));          if (NS_SUCCEEDED(rv)) {            nsCOMPtr<nsIDOMElement> domElement;// XXX This should be merged into nsIDocument            nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(iDoc, &rv);            if (NS_SUCCEEDED(rv) && htmlDoc) {              rv = htmlDoc->GetElementById(elementId, getter_AddRefs(domElement));            }#ifdef INCLUDE_XUL            else {              nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(iDoc, &rv);              if (NS_SUCCEEDED(rv) && xulDoc) {                rv = xulDoc->GetElementById(elementId, getter_AddRefs(domElement));              }            }#endif // INCLUDE_XUL            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;                nsresult gotFrame = nsGenericHTMLElement::GetPrimaryFrame(node, control);                isFormElement = NS_SUCCEEDED(gotFrame) && control;              }            }          }        } else { // --- No FOR attribute, we are a label for our first child element          PRInt32 numNodes;          rv = mInner.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;                  nsresult gotFrame = nsGenericHTMLElement::GetPrimaryFrame(node, control);                  isFormElement = NS_SUCCEEDED(gotFrame) && control;                }              }            }          }        }      } // 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;}