nsCOMPtr<nsIDOMNode> parentNode;  GetParentNode(getter_AddRefs(parentNode));  if (parentNode) { nsresult res; res = parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), (void**)&aSelectElement);   if (NS_FAILED(res)) { nsCOMPtr<nsIDOMHTMLOptGroupElement> optgroupElement;  while (parentNode) {  optgroupElement = do_QueryInterface(parentNode);  if (optgroupElement) { nsIDOMNode* tmpNode = parentNode.get();  tmpNode->GetParentNode(getter_AddRefs(parentNode)); } else { break; } }  if (parentNode) { parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), (void**)&aSelectElement); }
nsCOMPtr<nsIContent> parent; nsCOMPtr<nsIContent> prevParent; GetParent(*getter_AddRefs(parent)); while (parent) { CallQueryInterface(parent, aSelectElement); if (*aSelectElement) { break;
nsHTMLOptionElement::GetSelect(nsIDOMHTMLSelectElement *&aSelectElement){  aSelectElement = nsnull;  // Get the containing element (Either a select or an optGroup)  nsCOMPtr<nsIDOMNode> parentNode;  GetParentNode(getter_AddRefs(parentNode));  if (parentNode) {    nsresult res;    res = parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement),                                     (void**)&aSelectElement);    // If we are in an OptGroup we need to GetParentNode again (at least once)    if (NS_FAILED(res)) {      nsCOMPtr<nsIDOMHTMLOptGroupElement> optgroupElement;      while (parentNode) { // Be ready for nested OptGroups        // Don't need the optgroupElement, just seeing if it IS one.        optgroupElement = do_QueryInterface(parentNode);        if (optgroupElement) {          nsIDOMNode* tmpNode = parentNode.get();          tmpNode->GetParentNode(getter_AddRefs(parentNode));        } else {          break; // Break out if not a OptGroup (hopefully we have a select)        }      }      if (parentNode) {        parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement),                                   (void**)&aSelectElement);      }    }  }}