Commit 419eabf9 authored by bryner%netscape.com's avatar bryner%netscape.com
Browse files

Make sure a new image frame is constructed if the src of an image is changed...

Make sure a new image frame is constructed if the src of an image is changed and we don't have an image frame for the element (bug 228280). r=dbaron, sr=jst, a=dbaron.
parent d7b787b1
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ public:
protected:
  nsresult SetSrcInner(nsIURI* aBaseURL, const nsAString& aSrc);

  nsresult GetImageFrame(nsIImageFrame** aImageFrame);
  void GetImageFrame(nsIImageFrame** aImageFrame);
  nsresult GetXY(PRInt32* aX, PRInt32* aY);
  nsresult GetWidthHeight(PRInt32* aWidth, PRInt32* aHeight);

@@ -262,19 +262,19 @@ NS_IMPL_STRING_ATTR(nsHTMLImageElement, LongDesc, longdesc)
NS_IMPL_STRING_ATTR(nsHTMLImageElement, UseMap, usemap)
NS_IMPL_PIXEL_ATTR(nsHTMLImageElement, Vspace, vspace)

nsresult
void
nsHTMLImageElement::GetImageFrame(nsIImageFrame** aImageFrame)
{
  NS_ENSURE_ARG_POINTER(aImageFrame);
  *aImageFrame = nsnull;
  // If we have no parent, then we won't have a frame yet
  if (!mParent)
    return;

  nsIFrame* frame = GetPrimaryFrame(PR_TRUE);

  if (frame) {
    CallQueryInterface(frame, aImageFrame);
  }

  return NS_OK;
}

NS_IMETHODIMP
@@ -384,7 +384,7 @@ nsHTMLImageElement::GetWidthHeight(PRInt32* aWidth, PRInt32* aHeight)
    *aWidth = 0;
  }

  nsIImageFrame* imageFrame = nsnull;
  nsIImageFrame* imageFrame;
  GetImageFrame(&imageFrame);

  nsIFrame* frame = nsnull;
@@ -547,6 +547,16 @@ nsHTMLImageElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
      (aAttribute == nsHTMLAtoms::align)) {
    aHint = NS_STYLE_HINT_FRAMECHANGE;
  }
  else if (aAttribute == nsHTMLAtoms::src) {
    // If 'src' changed and we don't have a real image frame,
    // we need to cause a reframe.
    nsIImageFrame* imageFrame;
    // cast away |const| because the underlying interfaces don't use it.
    nsHTMLImageElement* mutable_this = NS_CONST_CAST(nsHTMLImageElement*,
                                                     this);
    mutable_this->GetImageFrame(&imageFrame);
    aHint = imageFrame ? NS_STYLE_HINT_CONTENT : NS_STYLE_HINT_FRAMECHANGE;
  }
  else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
    if (!GetImageMappedAttributesImpact(aAttribute, aHint)) {
      if (!GetImageBorderAttributeImpact(aAttribute, aHint)) {
@@ -896,15 +906,15 @@ nsHTMLImageElement::GetNaturalHeight(PRInt32* aNaturalHeight)

  *aNaturalHeight = 0;

  nsIImageFrame* imageFrame = nsnull;
  nsresult rv = GetImageFrame(&imageFrame);
  nsIImageFrame* imageFrame;
  GetImageFrame(&imageFrame);

  if (NS_FAILED(rv) || !imageFrame)
  if (!imageFrame)
    return NS_OK; // don't throw JS exceptions in this case

  PRUint32 width, height;

  rv = imageFrame->GetNaturalImageSize(&width, &height);
  nsresult rv = imageFrame->GetNaturalImageSize(&width, &height);

  if (NS_FAILED(rv))
    return NS_OK;
@@ -922,14 +932,14 @@ nsHTMLImageElement::GetNaturalWidth(PRInt32* aNaturalWidth)
  *aNaturalWidth = 0;

  nsIImageFrame* imageFrame;
  nsresult rv = GetImageFrame(&imageFrame);
  GetImageFrame(&imageFrame);

  if (NS_FAILED(rv) || !imageFrame)
  if (!imageFrame)
    return NS_OK; // don't throw JS exceptions in this case

  PRUint32 width, height;

  rv = imageFrame->GetNaturalImageSize(&width, &height);
  nsresult rv = imageFrame->GetNaturalImageSize(&width, &height);

  if (NS_FAILED(rv))
    return NS_OK;