nsCOMPtr<nsIDocument> doc; nsresult rv = GetDocument(*getter_AddRefs(doc)); if (NS_SUCCEEDED(rv) && doc) {  PRInt32 numShells = doc->GetNumberOfShells(); nsCOMPtr<nsIPresContext> context; for (PRInt32 i=0; i<numShells; i++) { nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i)); if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }  rv = shell->GetPresContext(getter_AddRefs(context)); if (NS_FAILED(rv)) { break; } if (!context) { rv = NS_ERROR_NULL_POINTER; break; }  rv = SetFocus(context); if (NS_FAILED(rv)) { break; } } }  return rv;
nsCOMPtr<nsIPresContext> presContext; nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext)); return SetFocus(presContext);
nsHTMLTextAreaElement::Focus() {  nsCOMPtr<nsIDocument> doc; // Strong  nsresult rv = GetDocument(*getter_AddRefs(doc));  if (NS_SUCCEEDED(rv) && doc) {    PRInt32 numShells = doc->GetNumberOfShells();    nsCOMPtr<nsIPresContext> context;    for (PRInt32 i=0; i<numShells; i++)     {      nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));      if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }      rv = shell->GetPresContext(getter_AddRefs(context));      if (NS_FAILED(rv)) { break; }      if (!context) { rv = NS_ERROR_NULL_POINTER; break; }      rv = SetFocus(context);      if (NS_FAILED(rv)) { break; }    }  }  return rv;}