if (NS_FAILED(result)) return result;
NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc,                                  nsIPresShell   *aPresShell, PRUint32 aFlags){  NS_PRECONDITION(aDoc && aPresShell, "bad arg");  if (!aDoc || !aPresShell)    return NS_ERROR_NULL_POINTER;  nsresult result = NS_ERROR_NULL_POINTER;  // Init the base editor  result = nsEditor::Init(aDoc, aPresShell, aFlags);  if (NS_FAILED(result)) { return result; }  nsCOMPtr<nsIDOMElement> bodyElement;  result = nsEditor::GetBodyElement(getter_AddRefs(bodyElement));  if (NS_FAILED(result)) { return result; }  if (!bodyElement) { return NS_ERROR_NULL_POINTER; }  // init the type-in state  mTypeInState = new TypeInState();  if (!mTypeInState) {return NS_ERROR_NULL_POINTER;}  NS_ADDREF(mTypeInState);  nsCOMPtr<nsIDOMSelection>selection;  result = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(result)) { return result; }  if (selection)   {    nsCOMPtr<nsIDOMSelectionListener>listener;    listener = do_QueryInterface(mTypeInState);    if (listener) {      selection->AddSelectionListener(listener);     }  }  // Set up a DTD    XXX XXX   // HACK: This should have happened in a document specific way  //       in nsEditor::Init(), but we dont' have a way to do that yet  result = nsComponentManager::CreateInstance(kCNavDTDCID, nsnull,                                          NS_GET_IID(nsIDTD), getter_AddRefs(mDTD));  if (!mDTD) result = NS_ERROR_FAILURE;  // Init the rules system  // XXX: ERROR CHECKING should InitRules return an error, and then we could check it here?  InitRules();  EnableUndo(PR_TRUE);   return result;}