if (IsInDoc()) {
nsIDocument* doc = GetCurrentDoc(); if (doc) {
nsHTMLImageElement::GetWidthHeight(){  nsSize size(0,0);  if (IsInDoc()) {    // Flush all pending notifications so that our frames are up to date.    // If we're not in a document, we don't have a frame anyway, so we    // don't care.    GetOwnerDoc()->FlushPendingNotifications(Flush_Layout);  }  nsIImageFrame* imageFrame;  GetImageFrame(&imageFrame);  nsIFrame* frame = nsnull;  if (imageFrame) {    CallQueryInterface(imageFrame, &frame);    NS_WARN_IF_FALSE(frame,"Should not happen - image frame is not frame");  }  if (frame) {    // XXX we could put an accessor on nsIImageFrame to return its    // mComputedSize.....    size = frame->GetSize();    nsMargin margin;    frame->CalcBorderPadding(margin);    size.height -= margin.top + margin.bottom;    size.width -= margin.left + margin.right;    nsPresContext *context = GetPresContext();    if (context) {      float t2p;      t2p = context->TwipsToPixels();      size.width = NSTwipsToIntPixels(size.width, t2p);      size.height = NSTwipsToIntPixels(size.height, t2p);    }  } else {    nsHTMLValue value;    nsCOMPtr<imgIContainer> image;    if (mCurrentRequest) {      mCurrentRequest->GetImage(getter_AddRefs(image));    }    if (GetHTMLAttribute(nsHTMLAtoms::width,                         value) == NS_CONTENT_ATTR_HAS_VALUE) {      size.width = value.GetIntValue();    } else if (image) {      image->GetWidth(&size.width);    }    if (GetHTMLAttribute(nsHTMLAtoms::height,                         value) == NS_CONTENT_ATTR_HAS_VALUE) {      size.height = value.GetIntValue();    } else if (image) {      image->GetHeight(&size.height);    }  }  return size;}