Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
nsImageFrame Class Reference

#include <nsImageFrame.h>

Inheritance diagram for nsImageFrame:
Inheritance graph
[legend]
Collaboration diagram for nsImageFrame:
Collaboration graph
[legend]

List of all members.

Classes

class  IconLoad

Public Member Functions

 nsImageFrame ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
NS_IMETHOD Destroy (nsPresContext *aPresContext)
NS_IMETHOD Init (nsPresContext *aPresContext, nsIContent *aContent, nsIFrame *aParent, nsStyleContext *aContext, nsIFrame *aPrevInFlow)
NS_IMETHOD Paint (nsPresContext *aPresContext, nsIRenderingContext &aRenderingContext, const nsRect &aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags=0)
NS_IMETHOD Reflow (nsPresContext *aPresContext, nsHTMLReflowMetrics &aDesiredSize, const nsHTMLReflowState &aReflowState, nsReflowStatus &aStatus)
NS_IMETHOD CanContinueTextRun (PRBool &aContinueTextRun) const
NS_IMETHOD GetContentForEvent (nsPresContext *aPresContext, nsEvent *aEvent, nsIContent **aContent)
NS_IMETHOD HandleEvent (nsPresContext *aPresContext, nsGUIEvent *aEvent, nsEventStatus *aEventStatus)
NS_IMETHOD GetCursor (const nsPoint &aPoint, nsIFrame::Cursor &aCursor)
NS_IMETHOD AttributeChanged (nsIContent *aChild, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
virtual nsIAtomGetType () const
NS_IMETHOD GetImageMap (nsPresContext *aPresContext, nsIImageMap **aImageMap)
NS_IMETHOD GetIntrinsicImageSize (nsSize &aSize)

Static Public Member Functions

static void ReleaseGlobals ()

Protected Member Functions

 NS_IMETHOD_ (nsrefcnt) AddRef(void)
 NS_IMETHOD_ (nsrefcnt) Release(void)
virtual ~nsImageFrame ()
virtual void GetDesiredSize (nsPresContext *aPresContext, const nsHTMLReflowState &aReflowState, nsHTMLReflowMetrics &aDesiredSize)
nsImageMapGetImageMap (nsPresContext *aPresContext)
void TriggerLink (nsPresContext *aPresContext, nsIURI *aURI, const nsString &aTargetSpec, PRBool aClick)
PRBool IsServerImageMap ()
void TranslateEventCoords (const nsPoint &aPoint, nsPoint &aResult)
PRBool GetAnchorHREFAndTarget (nsIURI **aHref, nsString &aTarget)
void MeasureString (const PRUnichar *aString, PRInt32 aLength, nscoord aMaxWidth, PRUint32 &aMaxFit, nsIRenderingContext &aContext)
void DisplayAltText (nsPresContext *aPresContext, nsIRenderingContext &aRenderingContext, const nsString &aAltText, const nsRect &aRect)
void DisplayAltFeedback (nsPresContext *aPresContext, nsIRenderingContext &aRenderingContext, imgIRequest *aRequest)
nsRect GetInnerArea () const
nsresult OnStartContainer (imgIRequest *aRequest, imgIContainer *aImage)
nsresult OnDataAvailable (imgIRequest *aRequest, gfxIImageFrame *aFrame, const nsRect *rect)
nsresult OnStopDecode (imgIRequest *aRequest, nsresult aStatus, const PRUnichar *aStatusArg)
nsresult FrameChanged (imgIContainer *aContainer, gfxIImageFrame *aNewframe, nsRect *aDirtyRect)

Private Member Functions

void SpecToURI (const nsAString &aSpec, nsIIOService *aIOService, nsIURI **aURI)
void GetLoadGroup (nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
nscoord GetContinuationOffset (nscoord *aWidth=0) const
void GetDocumentCharacterSet (nsACString &aCharset) const
PRBool RecalculateTransform (imgIContainer *aImage)
 This function will recalculate mTransform.
PRBool IsPendingLoad (imgIRequest *aRequest) const
 Helper functions to check whether the request or image container corresponds to a load we don't care about.
PRBool IsPendingLoad (imgIContainer *aContainer) const
nsRect SourceRectToDest (const nsRect &aRect)
 Function to convert a dirty rect in the source image to a dirty rect for the image frame.
nsresult HandleLoadError (PRInt16 aImageStatus)
 Function to call when a load fails; this handles things like alt text, broken image icons, etc.
nsresult LoadIcons (nsPresContext *aPresContext)
nsresult LoadIcon (const nsAString &aSpec, nsPresContext *aPresContext, imgIRequest **aRequest)
PRBool HandleIconLoads (imgIRequest *aRequest, PRBool aCompleted)
void InvalidateIcon ()

Private Attributes

nsImageMapmImageMap
nsCOMPtr< imgIDecoderObservermListener
nsSize mComputedSize
nsSize mIntrinsicSize
nsTransform2D mTransform
nsMargin mBorderPadding

Static Private Attributes

static nsIIOServicesIOService
static IconLoadgIconLoad = nsnull

Friends

class nsImageListener

Detailed Description

Definition at line 84 of file nsImageFrame.h.


Constructor & Destructor Documentation

Definition at line 186 of file nsImageFrame.cpp.

                           :
  mComputedSize(0, 0),
  mIntrinsicSize(0, 0)
{
  // We assume our size is not constrained and we haven't gotten an
  // initial reflow yet, so don't touch those flags.
}
nsImageFrame::~nsImageFrame ( ) [protected, virtual]

Definition at line 194 of file nsImageFrame.cpp.

{
}

Member Function Documentation

NS_IMETHODIMP nsImageFrame::AttributeChanged ( nsIContent aChild,
PRInt32  aNameSpaceID,
nsIAtom aAttribute,
PRInt32  aModType 
)

Definition at line 1778 of file nsImageFrame.cpp.

{
  nsresult rv = nsSplittableFrame::AttributeChanged(aChild, aNameSpaceID,
                                                    aAttribute, aModType);
  if (NS_FAILED(rv)) {
    return rv;
  }
  if (nsHTMLAtoms::alt == aAttribute)
  {
    mState |= NS_FRAME_IS_DIRTY;
    mParent->ReflowDirtyChild(GetPresContext()->PresShell(), (nsIFrame*) this);
  }

  return NS_OK;
}
NS_IMETHODIMP nsImageFrame::CanContinueTextRun ( PRBool aContinueTextRun) const

Definition at line 1640 of file nsImageFrame.cpp.

{
  // images really CAN continue text runs, but the textFrame needs to be 
  // educated before we can indicate that it can. For now, we handle the fixing up 
  // of max element widths in nsLineLayout::VerticalAlignFrames, but hopefully
  // this can be eliminated and the textFrame can be convinced to handle inlines
  // that take up space in text runs.

  aContinueTextRun = PR_FALSE;
  return NS_OK;
}

Definition at line 251 of file nsImageFrame.cpp.

{
  // Tell our image map, if there is one, to clean up
  // This causes the nsImageMap to unregister itself as
  // a DOM listener.
  if (mImageMap) {
    mImageMap->Destroy();
    NS_RELEASE(mImageMap);
  }

  // set the frame to null so we don't send messages to a dead object.
  if (mListener) {
    nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
    if (imageLoader) {
      imageLoader->RemoveObserver(mListener);
    }
    
    NS_REINTERPRET_CAST(nsImageListener*, mListener.get())->SetFrame(nsnull);
  }
  
  mListener = nsnull;

  return nsSplittableFrame::Destroy(aPresContext);
}

Here is the call graph for this function:

void nsImageFrame::DisplayAltFeedback ( nsPresContext aPresContext,
nsIRenderingContext aRenderingContext,
imgIRequest aRequest 
) [protected]

Definition at line 1185 of file nsImageFrame.cpp.

{
  // Calculate the inner area
  nsRect  inner = GetInnerArea();

  // Display a recessed one pixel border
  nscoord borderEdgeWidth;
  float   p2t = aPresContext->ScaledPixelsToTwips();
  borderEdgeWidth = NSIntPixelsToTwips(ALT_BORDER_WIDTH, p2t);

  // if inner area is empty, then make it big enough for at least the icon
  if (inner.IsEmpty()){
    inner.SizeTo(2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)),
                 2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)));
  }

  // Make sure we have enough room to actually render the border within
  // our frame bounds
  if ((inner.width < 2 * borderEdgeWidth) || (inner.height < 2 * borderEdgeWidth)) {
    return;
  }

  // Paint the border
  nsRecessedBorder recessedBorder(borderEdgeWidth);
  nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, inner,
                              inner, recessedBorder, mStyleContext, 0);

  // Adjust the inner rect to account for the one pixel recessed border,
  // and a six pixel padding on each edge
  inner.Deflate(NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t), 
                NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t));
  if (inner.IsEmpty()) {
    return;
  }

  // Clip so we don't render outside the inner rect
  aRenderingContext.PushState();
  aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect);

  PRBool dispIcon = gIconLoad ? gIconLoad->mPrefShowPlaceholders : PR_TRUE;

  // Check if we should display image placeholders
  if (dispIcon) {
    PRInt32 size = NSIntPixelsToTwips(ICON_SIZE, p2t);

    PRBool iconUsed = PR_FALSE;

    // see if the icon images are present...
    if (gIconLoad && gIconLoad->mIconsLoaded) {
      // pick the correct image
      nsCOMPtr<imgIContainer> imgCon;
      if (aRequest) {
        aRequest->GetImage(getter_AddRefs(imgCon));
      }
      if (imgCon) {
        // draw it
        nsRect source(0,0,size,size);
        nsRect dest(inner.x,inner.y,size,size);
        aRenderingContext.DrawImage(imgCon, source, dest);
        iconUsed = PR_TRUE;
      }
    }

    // if we could not draw the image, then just draw some grafitti
    if (!iconUsed) {
      nscolor oldColor;
      aRenderingContext.DrawRect(0,0,size,size);
      aRenderingContext.GetColor(oldColor);
      aRenderingContext.SetColor(NS_RGB(0xFF,0,0));
      aRenderingContext.FillEllipse(NS_STATIC_CAST(int,size/2),NS_STATIC_CAST(int,size/2),
                                    NS_STATIC_CAST(int,(size/2)-(2*p2t)),NS_STATIC_CAST(int,(size/2)-(2*p2t)));
      aRenderingContext.SetColor(oldColor);
    }  

    // Reduce the inner rect by the width of the icon, and leave an
    // additional ICON_PADDING pixels for padding
    PRInt32 iconWidth = NSIntPixelsToTwips(ICON_SIZE + ICON_PADDING, p2t);
    inner.x += iconWidth;
    inner.width -= iconWidth;
  }

  // If there's still room, display the alt-text
  if (!inner.IsEmpty()) {
    nsIContent* content = GetContent();
    if (content) {
      nsXPIDLString altText;
      nsCSSFrameConstructor::GetAlternateTextFor(content, content->Tag(),
                                                 altText);
      DisplayAltText(aPresContext, aRenderingContext, altText, inner);
    }
  }

  aRenderingContext.PopState();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::DisplayAltText ( nsPresContext aPresContext,
nsIRenderingContext aRenderingContext,
const nsString aAltText,
const nsRect aRect 
) [protected]

Definition at line 1124 of file nsImageFrame.cpp.

{
  // Set font and color
  aRenderingContext.SetColor(GetStyleColor()->mColor);
  SetFontFromStyle(&aRenderingContext, mStyleContext);

  // Format the text to display within the formatting rect
  nsIFontMetrics* fm;
  aRenderingContext.GetFontMetrics(fm);

  nscoord maxAscent, maxDescent, height;
  fm->GetMaxAscent(maxAscent);
  fm->GetMaxDescent(maxDescent);
  fm->GetHeight(height);

  // XXX It would be nice if there was a way to have the font metrics tell
  // use where to break the text given a maximum width. At a minimum we need
  // to be able to get the break character...
  const PRUnichar* str = aAltText.get();
  PRInt32          strLen = aAltText.Length();
  nscoord          y = aRect.y;
  // Always show the first line, even if we have to clip it below
  PRBool firstLine = PR_TRUE;
  while ((strLen > 0) && (firstLine || (y + maxDescent) < aRect.YMost())) {
    // Determine how much of the text to display on this line
    PRUint32  maxFit;  // number of characters that fit
    MeasureString(str, strLen, aRect.width, maxFit, aRenderingContext);
    
    // Display the text
    aRenderingContext.DrawString(str, maxFit, aRect.x, y + maxAscent);

    // Move to the next line
    str += maxFit;
    strLen -= maxFit;
    y += height;
    firstLine = PR_FALSE;
  }

  NS_RELEASE(fm);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsImageFrame::FrameChanged ( imgIContainer aContainer,
gfxIImageFrame aNewframe,
nsRect aDirtyRect 
) [protected]

Definition at line 707 of file nsImageFrame.cpp.

{
  if (!GetStyleVisibility()->IsVisible()) {
    return NS_OK;
  }

  if (IsPendingLoad(aContainer)) {
    // We don't care about it
    return NS_OK;
  }
  
  nsRect r = SourceRectToDest(*aDirtyRect);

  // Update border+content to account for image change
  Invalidate(r, PR_FALSE);
  return NS_OK;
}

Here is the call graph for this function:

PRBool nsImageFrame::GetAnchorHREFAndTarget ( nsIURI **  aHref,
nsString aTarget 
) [protected]

Definition at line 1616 of file nsImageFrame.cpp.

{
  PRBool status = PR_FALSE;
  aTarget.Truncate();

  // Walk up the content tree, looking for an nsIDOMAnchorElement
  for (nsIContent* content = mContent->GetParent();
       content; content = content->GetParent()) {
    nsCOMPtr<nsILink> link(do_QueryInterface(content));
    if (link) {
      link->GetHrefURI(aHref);
      status = (*aHref != nsnull);

      nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(content));
      if (anchor) {
        anchor->GetTarget(aTarget);
      }
      break;
    }
  }
  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsImageFrame::GetContentForEvent ( nsPresContext aPresContext,
nsEvent aEvent,
nsIContent **  aContent 
)

Definition at line 1654 of file nsImageFrame.cpp.

{
  NS_ENSURE_ARG_POINTER(aContent);
  nsImageMap* map;
  map = GetImageMap(aPresContext);

  if (nsnull != map) {
    nsPoint p;
    TranslateEventCoords(aEvent->point, p);
    PRBool inside = PR_FALSE;
    nsCOMPtr<nsIContent> area;
    inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
    if (inside && area) {
      *aContent = area;
      NS_ADDREF(*aContent);
      return NS_OK;
    }
  }

  *aContent = GetContent();
  NS_IF_ADDREF(*aContent);
  return NS_OK;
}

Here is the call graph for this function:

nscoord nsImageFrame::GetContinuationOffset ( nscoord aWidth = 0) const [private]

Definition at line 938 of file nsImageFrame.cpp.

{
  nscoord offset = 0;
  if (aWidth) {
    *aWidth = 0;
  }

  if (mPrevInFlow) {
    for (nsIFrame* prevInFlow = mPrevInFlow ; prevInFlow; prevInFlow = prevInFlow->GetPrevInFlow()) {
      nsRect rect = prevInFlow->GetRect();
      if (aWidth) {
        *aWidth = rect.width;
      }
      offset += rect.height;
    }
    offset -= mBorderPadding.top;
    offset = PR_MAX(0, offset);
  }
  return offset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1746 of file nsImageFrame.cpp.

{
  nsPresContext* context = GetPresContext();
  nsImageMap* map = GetImageMap(context);
  if (nsnull != map) {
    nsPoint p;
    TranslateEventCoords(aPoint, p);
    nsCOMPtr<nsIContent> area;
    if (map->IsInside(p.x, p.y, getter_AddRefs(area))) {
      // Use the cursor from the style of the *area* element.
      // XXX Using the image as the parent style context isn't
      // technically correct, but it's probably the right thing to do
      // here, since it means that areas on which the cursor isn't
      // specified will inherit the style from the image.
      nsRefPtr<nsStyleContext> areaStyle = 
        GetPresContext()->PresShell()->StyleSet()->
          ResolveStyleFor(area, GetStyleContext());
      if (areaStyle) {
        FillCursorInformationFromStyle(areaStyle->GetStyleUserInterface(),
                                       aCursor);
        if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
          aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
        }
        return NS_OK;
      }
    }
  }
  return nsFrame::GetCursor(aPoint, aCursor);
}

Here is the call graph for this function:

void nsImageFrame::GetDesiredSize ( nsPresContext aPresContext,
const nsHTMLReflowState aReflowState,
nsHTMLReflowMetrics aDesiredSize 
) [protected, virtual]

Definition at line 736 of file nsImageFrame.cpp.

{
  // if mIntrinsicSize.width and height are 0, then we should
  // check to see if the size is already known by the image container.
  if (mIntrinsicSize.width == 0 && mIntrinsicSize.height == 0) {
    nsCOMPtr<imgIRequest> currentRequest;
    nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
    if (imageLoader) {
      imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                              getter_AddRefs(currentRequest));
    }
    nsCOMPtr<imgIContainer> currentContainer;
    if (currentRequest) {
      currentRequest->GetImage(getter_AddRefs(currentContainer));
    }
      
    float p2t;
    p2t = aPresContext->PixelsToTwips();

    if (currentContainer) {
      RecalculateTransform(currentContainer);
    } else {
      // image request is null or image size not known, probably an
      // invalid image specified
      // - make the image big enough for the icon (it may not be
      // used if inline alt expansion is used instead)
      // XXX: we need this in composer, but it is also good for
      // XXX: general quirks mode to always have room for the icon
      if (aPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
        mIntrinsicSize.SizeTo(NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t),
                              NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t));
      }
      RecalculateTransform(nsnull);
    }
  }

  // Handle intrinsic sizes and their interaction with
  // {min-,max-,}{width,height} according to the rules in
  // http://www.w3.org/TR/CSS21/visudet.html#min-max-widths

  // Note: throughout the following section of the function, I avoid
  // a * (b / c) because of its reduced accuracy relative to a * b / c
  // or (a * b) / c (which are equivalent).

  // convert from normal twips to scaled twips (printing...)
  float t2st = aPresContext->TwipsToPixels() *
    aPresContext->ScaledPixelsToTwips(); // twips to scaled twips
  nscoord intrinsicWidth =
      NSToCoordRound(float(mIntrinsicSize.width) * t2st);
  nscoord intrinsicHeight =
      NSToCoordRound(float(mIntrinsicSize.height) * t2st);

  // Determine whether the image has fixed content width
  nscoord width = aReflowState.mComputedWidth;
  nscoord minWidth = aReflowState.mComputedMinWidth;
  nscoord maxWidth = aReflowState.mComputedMaxWidth;

  // Determine whether the image has fixed content height
  nscoord height = aReflowState.mComputedHeight;
  nscoord minHeight = aReflowState.mComputedMinHeight;
  nscoord maxHeight = aReflowState.mComputedMaxHeight;

  PRBool isAutoWidth = width == NS_INTRINSICSIZE;
  PRBool isAutoHeight = height == NS_UNCONSTRAINEDSIZE;
  if (isAutoWidth) {
    if (isAutoHeight) {

      // 'auto' width, 'auto' height
      // XXX nsHTMLReflowState should already ensure this
      if (minWidth > maxWidth)
        maxWidth = minWidth;
      if (minHeight > maxHeight)
        maxHeight = minHeight;

      nscoord heightAtMaxWidth, heightAtMinWidth,
              widthAtMaxHeight, widthAtMinHeight;
      if (intrinsicWidth > 0) {
        heightAtMaxWidth = maxWidth * intrinsicHeight / intrinsicWidth;
        if (heightAtMaxWidth < minHeight)
          heightAtMaxWidth = minHeight;
        heightAtMinWidth = minWidth * intrinsicHeight / intrinsicWidth;
        if (heightAtMinWidth > maxHeight)
          heightAtMinWidth = maxHeight;
      } else {
        heightAtMaxWidth = intrinsicHeight;
        heightAtMinWidth = intrinsicHeight;
      }

      if (intrinsicHeight > 0) {
        widthAtMaxHeight = maxHeight * intrinsicWidth / intrinsicHeight;
        if (widthAtMaxHeight < minWidth)
          widthAtMaxHeight = minWidth;
        widthAtMinHeight = minHeight * intrinsicWidth / intrinsicHeight;
        if (widthAtMinHeight > maxWidth)
          widthAtMinHeight = maxWidth;
      } else {
        widthAtMaxHeight = intrinsicWidth;
        widthAtMinHeight = intrinsicWidth;
      }

      if (intrinsicWidth > maxWidth) {
        if (intrinsicHeight > maxHeight) {
          if (maxWidth * intrinsicHeight <= maxHeight * intrinsicWidth) {
            width = maxWidth;
            height = heightAtMaxWidth;
          } else {
            height = maxHeight;
            width = widthAtMaxHeight;
          }
        } else {
          width = maxWidth;
          height = heightAtMaxWidth;
        }
      } else if (intrinsicWidth < minWidth) {
        if (intrinsicHeight < minHeight) {
          if (minWidth * intrinsicHeight <= minHeight * intrinsicWidth) {
            height = minHeight;
            width = widthAtMinHeight;
          } else {
            width = minWidth;
            height = heightAtMinWidth;
          }
        } else {
          width = minWidth;
          height = heightAtMinWidth;
        }
      } else {
        if (intrinsicHeight > maxHeight) {
          height = maxHeight;
          width = widthAtMaxHeight;
        } else if (intrinsicHeight < minHeight) {
          height = minHeight;
          width = widthAtMinHeight;
        } else {
          width = intrinsicWidth;
          height = intrinsicHeight;
        }
      }

    } else {

      // 'auto' width, non-'auto' height
      // XXX nsHTMLReflowState should already ensure this
      height = MINMAX(height, minHeight, maxHeight);
      if (intrinsicHeight != 0) {
        width = intrinsicWidth * height / intrinsicHeight;
      } else {
        width = intrinsicWidth;
      }
      width = MINMAX(width, minWidth, maxWidth);

    }
  } else {
    if (isAutoHeight) {

      // non-'auto' width, 'auto' height
      // XXX nsHTMLReflowState should already ensure this
      width = MINMAX(width, minWidth, maxWidth);
      if (intrinsicWidth != 0) {
        height = intrinsicHeight * width / intrinsicWidth;
      } else {
        height = intrinsicHeight;
      }
      height = MINMAX(height, minHeight, maxHeight);

    } else {

      // non-'auto' width, non-'auto' height
      // XXX nsHTMLReflowState should already ensure this
      height = MINMAX(height, minHeight, maxHeight);
      // XXX nsHTMLReflowState should already ensure this
      width = MINMAX(width, minWidth, maxWidth);

    }
  }

  if (mComputedSize.width != width || mComputedSize.height != height) {
    mComputedSize.SizeTo(width, height);
    RecalculateTransform(nsnull);
  }

  aDesiredSize.width = mComputedSize.width;
  aDesiredSize.height = mComputedSize.height;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::GetDocumentCharacterSet ( nsACString &  aCharset) const [private]

Definition at line 1895 of file nsImageFrame.cpp.

{
  if (mContent) {
    NS_ASSERTION(mContent->GetDocument(),
                 "Frame still alive after content removed from document!");
    aCharset = mContent->GetDocument()->GetDocumentCharacterSet();
  }
}

Here is the caller graph for this function:

NS_IMETHODIMP nsImageFrame::GetImageMap ( nsPresContext aPresContext,
nsIImageMap **  aImageMap 
) [virtual]

Implements nsIImageFrame.

Definition at line 1495 of file nsImageFrame.cpp.

{
  nsImageMap *map = GetImageMap(aPresContext);
  return CallQueryInterface(map, aImageMap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsImageMap * nsImageFrame::GetImageMap ( nsPresContext aPresContext) [protected]

Definition at line 1502 of file nsImageFrame.cpp.

{
  if (!mImageMap) {
    nsIDocument* doc = mContent->GetDocument();
    if (!doc) {
      return nsnull;
    }

    nsAutoString usemap;
    mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap);

    nsCOMPtr<nsIDOMHTMLMapElement> map = nsImageMapUtils::FindImageMap(doc,usemap);
    if (map) {
      mImageMap = new nsImageMap();
      if (mImageMap) {
        NS_ADDREF(mImageMap);
        mImageMap->Init(aPresContext->PresShell(), this, map);
      }
    }
  }

  return mImageMap;
}

Here is the call graph for this function:

nsRect nsImageFrame::GetInnerArea ( ) const [protected]

Definition at line 924 of file nsImageFrame.cpp.

{
  nsRect r;
  r.x = mBorderPadding.left;
  r.y = mPrevInFlow ? 0 : mBorderPadding.top;
  r.width = mRect.width - mBorderPadding.left - mBorderPadding.right;
  r.height = mRect.height -
    (mPrevInFlow ? 0 : mBorderPadding.top) -
    (mNextInFlow ? 0 : mBorderPadding.bottom);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIImageFrame.

Definition at line 1848 of file nsImageFrame.cpp.

{
  aSize = mIntrinsicSize;
  return NS_OK;
}

Here is the caller graph for this function:

void nsImageFrame::GetLoadGroup ( nsPresContext aPresContext,
nsILoadGroup **  aLoadGroup 
) [inline, private]

Definition at line 1920 of file nsImageFrame.cpp.

{
  if (!aPresContext)
    return;

  NS_PRECONDITION(nsnull != aLoadGroup, "null OUT parameter pointer");

  nsIPresShell *shell = aPresContext->GetPresShell();

  if (!shell)
    return;

  nsIDocument *doc = shell->GetDocument();
  if (!doc)
    return;

  *aLoadGroup = doc->GetDocumentLoadGroup().get();  // already_AddRefed
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIAtom * nsImageFrame::GetType ( void  ) const [virtual]

Definition at line 1798 of file nsImageFrame.cpp.

{
  return nsLayoutAtoms::imageFrame;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsImageFrame::HandleEvent ( nsPresContext aPresContext,
nsGUIEvent aEvent,
nsEventStatus aEventStatus 
)

Definition at line 1682 of file nsImageFrame.cpp.

{
  NS_ENSURE_ARG_POINTER(aEventStatus);
  nsImageMap* map;

  switch (aEvent->message) {
  case NS_MOUSE_LEFT_BUTTON_UP:
  case NS_MOUSE_MOVE:
    {
      map = GetImageMap(aPresContext);
      PRBool isServerMap = IsServerImageMap();
      if ((nsnull != map) || isServerMap) {
        nsPoint p;
        TranslateEventCoords(aEvent->point, p);
        PRBool inside = PR_FALSE;
        // Even though client-side image map triggering happens
        // through content, we need to make sure we're not inside
        // (in case we deal with a case of both client-side and
        // sever-side on the same image - it happens!)
        if (nsnull != map) {
          nsCOMPtr<nsIContent> area;
          inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
        }

        if (!inside && isServerMap) {

          // Server side image maps use the href in a containing anchor
          // element to provide the basis for the destination url.
          nsCOMPtr<nsIURI> uri;
          nsAutoString target;
          if (GetAnchorHREFAndTarget(getter_AddRefs(uri), target)) {
            // XXX if the mouse is over/clicked in the border/padding area
            // we should probably just pretend nothing happened. Nav4
            // keeps the x,y coordinates positive as we do; IE doesn't
            // bother. Both of them send the click through even when the
            // mouse is over the border.
            if (p.x < 0) p.x = 0;
            if (p.y < 0) p.y = 0;
            nsCAutoString spec;
            uri->GetSpec(spec);
            spec += nsPrintfCString("?%d,%d", p.x, p.y);
            uri->SetSpec(spec);                
            
            PRBool clicked = PR_FALSE;
            if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
              *aEventStatus = nsEventStatus_eConsumeDoDefault; 
              clicked = PR_TRUE;
            }
            TriggerLink(aPresContext, uri, target, clicked);
          }
        }
      }
      break;
    }
    default:
      break;
  }

  return nsSplittableFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}

Here is the call graph for this function:

PRBool nsImageFrame::HandleIconLoads ( imgIRequest aRequest,
PRBool  aCompleted 
) [private]

Definition at line 1979 of file nsImageFrame.cpp.

{
  PRBool result = PR_FALSE;

  if (gIconLoad) {
    // check which image it is
    if (aRequest == gIconLoad->mLoadingImage ||
        aRequest == gIconLoad->mBrokenImage) {
      result = PR_TRUE;
      if (aLoaded && (++gIconLoad->mIconsLoaded == 2))
        gIconLoad->mLoadObserver = nsnull;
    }

#ifdef NOISY_ICON_LOADING
    if (gIconLoad->mIconsLoaded && result) {
      printf( "Icons Loaded: request for %s\n",
              aRequest == gIconLoad->mLoadingImage
                ? "mLoadingImage" : "mBrokenImage" );
    }
#endif
  }
  
#ifdef NOISY_ICON_LOADING
  printf( "HandleIconLoads returned %s (%p)\n", result ? "TRUE" : "FALSE", this);
#endif

  return result;
}

Here is the caller graph for this function:

nsresult nsImageFrame::HandleLoadError ( PRInt16  aImageStatus) [private]

Function to call when a load fails; this handles things like alt text, broken image icons, etc.

Returns NS_ERROR_FRAME_REPLACED if it called CantRenderReplacedElement, NS_OK otherwise.

Parameters:
aImageStatusthe status of the image (
See also:
nsIContentPolicy)

Definition at line 451 of file nsImageFrame.cpp.

{
  if (!NS_CP_ACCEPTED(aImageStatus) &&
      aImageStatus == nsIContentPolicy::REJECT_SERVER) {
    // Don't display any alt feedback in this case; we're blocking images
    // from that site and don't care to see anything from them
    return NS_OK;
  }
  
  // If we have an image map, don't do anything here
  // XXXbz Why?  This is what the code used to do, but there's no good
  // reason for it....

  nsAutoString usemap;
  mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap);    
  if (!usemap.IsEmpty()) {
    return NS_OK;
  }

  nsPresContext* presContext = GetPresContext();
  
  // Check if we want to use a placeholder box with an icon or just
  // let the the presShell make us into inline text.  Decide as follows:
  //
  //  - if our special "force icons" style is set, show an icon
  //  - else if our "do not show placeholders" pref is set, skip the icon
  //  - else:
  //  - if QuirksMode, and there is no alt attribute, and this is not an
  //    <object> (which could not possibly have such an attribute), show an
  //    icon.
  //  - if QuirksMode, and the IMG has a size, and the image is
  //    broken, not blocked, show an icon.
  //  - otherwise, skip the icon

  PRBool useSizedBox;
  
  const nsStyleUIReset* uiResetData = GetStyleUIReset();
  if (uiResetData->mForceBrokenImageIcon) {
    useSizedBox = PR_TRUE;
  }
  else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
    useSizedBox = PR_FALSE;
  }
  else {
    if (presContext->CompatibilityMode() != eCompatibility_NavQuirks) {
      useSizedBox = PR_FALSE;
    }
    else {
      // We are in quirks mode, so we can just check the tag name; no need to
      // check the namespace.
      nsINodeInfo *nodeInfo = mContent->GetNodeInfo();

      if (!mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::alt) &&
          nodeInfo &&
          !nodeInfo->Equals(nsHTMLAtoms::object)) {
        useSizedBox = PR_TRUE;
      }
      else if (!NS_CP_ACCEPTED(aImageStatus)) {
        useSizedBox = PR_FALSE;
      }
      else {
        // check whether we have fixed size
        useSizedBox = HaveFixedSize(GetStylePosition());
      }
    }
  }
  
  if (!useSizedBox) {
    // let the presShell handle converting this into the inline alt
    // text frame
    nsIFrame* primaryFrame = nsnull;
    if (mContent->IsContentOfType(nsIContent::eHTML) &&
        (mContent->Tag() == nsHTMLAtoms::object ||
         mContent->Tag() == nsHTMLAtoms::embed)) {
      // We have to try to get the primary frame for mContent, since for
      // <object> the frame CantRenderReplacedElement wants is the
      // ObjectFrame, not us (we're an anonymous frame then)....
      presContext->PresShell()->GetPrimaryFrameFor(mContent, &primaryFrame);
    }

    if (!primaryFrame) {
      primaryFrame = this;
    }     
    
    presContext->PresShell()->CantRenderReplacedElement(primaryFrame);
    return NS_ERROR_FRAME_REPLACED;
  }

  // we are handling it
  // invalidate the icon area (it may change states)   
  InvalidateIcon();
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsImageFrame::Init ( nsPresContext aPresContext,
nsIContent aContent,
nsIFrame aParent,
nsStyleContext aContext,
nsIFrame aPrevInFlow 
)

Definition at line 279 of file nsImageFrame.cpp.

{
  nsresult  rv = nsSplittableFrame::Init(aPresContext, aContent, aParent,
                                         aContext, aPrevInFlow);
  NS_ENSURE_SUCCESS(rv, rv);

  mListener = new nsImageListener(this);
  if (!mListener) return NS_ERROR_OUT_OF_MEMORY;

  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent);
  NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
  imageLoader->AddObserver(mListener);

  if (!gIconLoad)
    LoadIcons(aPresContext);

  nsCOMPtr<imgIRequest> currentRequest;
  imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                          getter_AddRefs(currentRequest));
  PRUint32 currentLoadStatus = imgIRequest::STATUS_ERROR;
  if (currentRequest) {
    currentRequest->GetImageStatus(&currentLoadStatus);

    // Give image loads associated with an image frame a small priority boost!
    nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(currentRequest);
    if (p)
      p->AdjustPriority(-1);
  }

  if (currentLoadStatus & imgIRequest::STATUS_ERROR) {
    PRInt16 imageStatus = nsIContentPolicy::ACCEPT;
    imageLoader->GetImageBlockingStatus(&imageStatus);
    rv = HandleLoadError(imageStatus);
  }
  // If we already have an image container, OnStartContainer won't be called
  // Set the animation mode here
  if (currentRequest) {
    nsCOMPtr<imgIContainer> image;
    currentRequest->GetImage(getter_AddRefs(image));
    if (image) {
      image->SetAnimationMode(aPresContext->ImageAnimationMode());
      // Ensure the animation (if any) is started.
      image->StartAnimation();
    }
  }

  return rv;
}

Here is the call graph for this function:

Definition at line 2008 of file nsImageFrame.cpp.

{
  // invalidate the inner area, where the icon lives

  nsPresContext *presContext = GetPresContext();
  float   p2t = presContext->ScaledPixelsToTwips();
  nsRect inner = GetInnerArea();

  nsRect rect(inner.x,
              inner.y,
              NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING, p2t),
              NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING, p2t));
  NS_ASSERTION(!rect.IsEmpty(), "icon rect cannot be empty!");
  // update image area
  Invalidate(rect, PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsImageFrame::IsPendingLoad ( imgIRequest aRequest) const [private]

Helper functions to check whether the request or image container corresponds to a load we don't care about.

Most of the decoder observer methods will bail early if these return true.

Definition at line 380 of file nsImageFrame.cpp.

{
  // Default to pending load in case of errors
  nsCOMPtr<nsIImageLoadingContent> imageLoader(do_QueryInterface(mContent));
  NS_ASSERTION(imageLoader, "No image loading content?");

  PRInt32 requestType = nsIImageLoadingContent::UNKNOWN_REQUEST;
  imageLoader->GetRequestType(aRequest, &requestType);

  return requestType != nsIImageLoadingContent::CURRENT_REQUEST;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsImageFrame::IsPendingLoad ( imgIContainer aContainer) const [private]

Definition at line 393 of file nsImageFrame.cpp.

{
  //  default to pending load in case of errors
  if (!aContainer) {
    NS_ERROR("No image container!");
    return PR_TRUE;
  }

  nsCOMPtr<nsIImageLoadingContent> imageLoader(do_QueryInterface(mContent));
  NS_ASSERTION(imageLoader, "No image loading content?");
  
  nsCOMPtr<imgIRequest> currentRequest;
  imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                          getter_AddRefs(currentRequest));
  if (!currentRequest) {
    NS_ERROR("No current request");
    return PR_TRUE;
  }

  nsCOMPtr<imgIContainer> currentContainer;
  currentRequest->GetImage(getter_AddRefs(currentContainer));

  return currentContainer != aContainer;
  
}

Here is the call graph for this function:

Definition at line 1569 of file nsImageFrame.cpp.

{
  nsAutoString ismap;
  return NS_CONTENT_ATTR_HAS_VALUE ==
    mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::ismap, ismap);
}

Here is the caller graph for this function:

nsresult nsImageFrame::LoadIcon ( const nsAString &  aSpec,
nsPresContext aPresContext,
imgIRequest **  aRequest 
) [private]

Definition at line 1855 of file nsImageFrame.cpp.

{
  nsresult rv = NS_OK;
  NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??");

  if (!sIOService) {
    static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
    rv = CallGetService(kIOServiceCID, &sIOService);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsCOMPtr<nsIURI> realURI;
  SpecToURI(aSpec, sIOService, getter_AddRefs(realURI));
 
  nsCOMPtr<imgILoader> il(do_GetService("@mozilla.org/image/loader;1", &rv));
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsILoadGroup> loadGroup;
  GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));

  // For icon loads, we don't need to merge with the loadgroup flags
  nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;

  return il->LoadImage(realURI,     /* icon URI */
                       nsnull,      /* initial document URI; this is only
                                       relevant for cookies, so does not
                                       apply to icons. */
                       nsnull,      /* referrer (not relevant for icons) */
                       loadGroup,
                       mListener,
                       nsnull,      /* Not associated with any particular document */
                       loadFlags,
                       nsnull,
                       nsnull,
                       aRequest);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsImageFrame::LoadIcons ( nsPresContext aPresContext) [private]

Definition at line 1939 of file nsImageFrame.cpp.

{
  NS_ASSERTION(!gIconLoad, "called LoadIcons twice");

  NS_NAMED_LITERAL_STRING(loadingSrc,"resource://gre/res/loading-image.gif"); 
  NS_NAMED_LITERAL_STRING(brokenSrc,"resource://gre/res/broken-image.gif");

  gIconLoad = new IconLoad(mListener);
  if (!gIconLoad) 
    return NS_ERROR_OUT_OF_MEMORY;
  NS_ADDREF(gIconLoad);

  nsresult rv;
  // create a loader and load the images
  rv = LoadIcon(loadingSrc,
                aPresContext,
                getter_AddRefs(gIconLoad->mLoadingImage));
#ifdef NOISY_ICON_LOADING
  printf("Loading request %p, rv=%u\n",
         gIconLoad->mLoadingImage.get(), rv);
#endif

  if (NS_FAILED(rv)) {
    return rv;
  }

  rv = LoadIcon(brokenSrc,
                aPresContext,
                getter_AddRefs(gIconLoad->mBrokenImage));
#ifdef NOISY_ICON_LOADING
  printf("Loading request %p, rv=%u\n",
         gIconLoad->mBrokenImage.get(), rv);
#endif

  // ImageLoader will callback into OnStartContainer, which will
  // handle the mIconsLoaded flag

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::MeasureString ( const PRUnichar aString,
PRInt32  aLength,
nscoord  aMaxWidth,
PRUint32 aMaxFit,
nsIRenderingContext aContext 
) [protected]

Definition at line 1063 of file nsImageFrame.cpp.

{
  nscoord totalWidth = 0;
  nscoord spaceWidth;
  aContext.GetWidth(' ', spaceWidth);

  aMaxFit = 0;
  while (aLength > 0) {
    // Find the next place we can line break
    PRUint32  len = aLength;
    PRBool    trailingSpace = PR_FALSE;
    for (PRInt32 i = 0; i < aLength; i++) {
      if (XP_IS_SPACE(aString[i]) && (i > 0)) {
        len = i;  // don't include the space when measuring
        trailingSpace = PR_TRUE;
        break;
      }
    }
  
    // Measure this chunk of text, and see if it fits
    nscoord width;
    aContext.GetWidth(aString, len, width);
    PRBool  fits = (totalWidth + width) <= aMaxWidth;

    // If it fits on the line, or it's the first word we've processed then
    // include it
    if (fits || (0 == totalWidth)) {
      // New piece fits
      totalWidth += width;

      // If there's a trailing space then see if it fits as well
      if (trailingSpace) {
        if ((totalWidth + spaceWidth) <= aMaxWidth) {
          totalWidth += spaceWidth;
        } else {
          // Space won't fit. Leave it at the end but don't include it in
          // the width
          fits = PR_FALSE;
        }

        len++;
      }

      aMaxFit += len;
      aString += len;
      aLength -= len;
    }

    if (!fits) {
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsImageFrame::OnDataAvailable ( imgIRequest aRequest,
gfxIImageFrame aFrame,
const nsRect rect 
) [protected]

Definition at line 588 of file nsImageFrame.cpp.

{
  // XXX do we need to make sure that the reflow from the
  // OnStartContainer has been processed before we start calling
  // invalidate?

  NS_ENSURE_ARG_POINTER(aRect);

  if (!(mState & IMAGE_GOTINITIALREFLOW)) {
    // Don't bother to do anything; we have a reflow coming up!
    return NS_OK;
  }
  
  // handle iconLoads first...
  if (HandleIconLoads(aRequest, PR_FALSE)) {
    // Image changed, invalidate
    Invalidate(*aRect, PR_FALSE);
    return NS_OK;
  }

  if (IsPendingLoad(aRequest)) {
    // We don't care
    return NS_OK;
  }

  // Don't invalidate if the current visible frame isn't the one the data is
  // from
  nsCOMPtr<imgIContainer> container;
  aRequest->GetImage(getter_AddRefs(container));
  if (container) {
    nsCOMPtr<gfxIImageFrame> currentFrame;
    container->GetCurrentFrame(getter_AddRefs(currentFrame));
    if (aFrame != currentFrame) {
      // just bail
      return NS_OK;
    }
  }

  nsRect r = SourceRectToDest(*aRect);
#ifdef DEBUG_decode
  printf("Source rect (%d,%d,%d,%d) -> invalidate dest rect (%d,%d,%d,%d)\n",
         aRect->x, aRect->y, aRect->width, aRect->height,
         r.x, r.y, r.width, r.height);
#endif

  Invalidate(r, PR_FALSE);
  
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsImageFrame::OnStartContainer ( imgIRequest aRequest,
imgIContainer aImage 
) [protected]

Definition at line 546 of file nsImageFrame.cpp.

{
  if (!aImage) return NS_ERROR_INVALID_ARG;

  // handle iconLoads first...
  if (HandleIconLoads(aRequest, PR_FALSE)) {
    return NS_OK;
  }

  /* Get requested animation policy from the pres context:
   *   normal = 0
   *   one frame = 1
   *   one loop = 2
   */
  nsPresContext *presContext = GetPresContext();
  aImage->SetAnimationMode(presContext->ImageAnimationMode());
  // Ensure the animation (if any) is started.
  aImage->StartAnimation();

  if (IsPendingLoad(aRequest)) {
    // We don't care
    return NS_OK;
  }
  
  RecalculateTransform(aImage);

  // Now we need to reflow if we have an unconstrained size and have
  // already gotten the initial reflow
  if (!(mState & IMAGE_SIZECONSTRAINED) && (mState & IMAGE_GOTINITIALREFLOW)) { 
    nsIPresShell *presShell = presContext->GetPresShell();
    NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
    NS_ASSERTION(presShell, "No PresShell.");
    if (mParent && presShell) { 
      mState |= NS_FRAME_IS_DIRTY;
      mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsImageFrame::OnStopDecode ( imgIRequest aRequest,
nsresult  aStatus,
const PRUnichar aStatusArg 
) [protected]

Definition at line 641 of file nsImageFrame.cpp.

{
  nsPresContext *presContext = GetPresContext();
  nsIPresShell *presShell = presContext->GetPresShell();
  NS_ASSERTION(presShell, "No PresShell.");

  // handle iconLoads first...
  if (HandleIconLoads(aRequest, NS_SUCCEEDED(aStatus))) {
    return NS_OK;
  }

  // Check what request type we're dealing with
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
  NS_ASSERTION(imageLoader, "Who's notifying us??");
  PRInt32 loadType = nsIImageLoadingContent::UNKNOWN_REQUEST;
  imageLoader->GetRequestType(aRequest, &loadType);
  if (loadType != nsIImageLoadingContent::CURRENT_REQUEST &&
      loadType != nsIImageLoadingContent::PENDING_REQUEST) {
    return NS_ERROR_FAILURE;
  }

  if (loadType == nsIImageLoadingContent::PENDING_REQUEST) {
    // May have to switch sizes here!
    PRBool intrinsicSizeChanged = PR_TRUE;
    if (NS_SUCCEEDED(aStatus)) {
      nsCOMPtr<imgIContainer> imageContainer;
      aRequest->GetImage(getter_AddRefs(imageContainer));
      NS_ASSERTION(imageContainer, "Successful load with no container?");
      intrinsicSizeChanged = RecalculateTransform(imageContainer);
    }
    else {
      // Have to size to 0,0 so that GetDesiredSize recalculates the size
      mIntrinsicSize.SizeTo(0, 0);
    }

    if (mState & IMAGE_GOTINITIALREFLOW) { // do nothing if we havn't gotten the inital reflow yet
      if (!(mState & IMAGE_SIZECONSTRAINED) && intrinsicSizeChanged) {
        NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
        if (mParent && presShell) { 
          mState |= NS_FRAME_IS_DIRTY;
          mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
        }
      } else {
        nsSize s = GetSize();
        nsRect r(0, 0, s.width, s.height);
        // Update border+content to account for image change
        Invalidate(r, PR_FALSE);
      }
    }
  }

  // if src failed to load, determine how to handle it: 
  //  - either render the ALT text in this frame, or let the presShell
  //  handle it
  if (NS_FAILED(aStatus) && aStatus != NS_ERROR_IMAGE_SRC_CHANGED) {
    PRInt16 imageStatus = nsIContentPolicy::ACCEPT;
    imageLoader->GetImageBlockingStatus(&imageStatus);
    HandleLoadError(imageStatus);
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_METHOD nsImageFrame::Paint ( nsPresContext aPresContext,
nsIRenderingContext aRenderingContext,
const nsRect aDirtyRect,
nsFramePaintLayer  aWhichLayer,
PRUint32  aFlags = 0 
)

Definition at line 1283 of file nsImageFrame.cpp.

{
  PRBool isVisible;
  if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && 
      isVisible && mRect.width && mRect.height) {
    // If painting is suppressed, we need to stop image painting.  We
    // have to cover <img> here because of input image controls.
    PRBool paintingSuppressed = PR_FALSE;
    aPresContext->PresShell()->IsPaintingSuppressed(&paintingSuppressed);
    if (paintingSuppressed) {
      return NS_OK;
    }

    // First paint background and borders, which should be in the
    // FOREGROUND or BACKGROUND paint layer if the element is
    // inline-level or block-level, respectively (bug 36710).  (See
    // CSS2 9.5, which is the rationale for paint layers.)
    const nsStyleDisplay* display = GetStyleDisplay();
    nsFramePaintLayer backgroundLayer = display->IsBlockLevel()
                                            ? NS_FRAME_PAINT_LAYER_BACKGROUND
                                            : NS_FRAME_PAINT_LAYER_FOREGROUND;
    if (aWhichLayer == backgroundLayer) {
      PaintSelf(aPresContext, aRenderingContext, aDirtyRect);
    }

    if (mComputedSize.width != 0 && mComputedSize.height != 0) {
      nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
      NS_ASSERTION(mContent, "Not an image loading content?");

      nsCOMPtr<imgIRequest> currentRequest;
      if (imageLoader) {
        imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                                getter_AddRefs(currentRequest));
      }
      
      nsCOMPtr<imgIContainer> imgCon;

      PRUint32 loadStatus = imgIRequest::STATUS_ERROR;

      if (currentRequest) {
        currentRequest->GetImage(getter_AddRefs(imgCon));
        currentRequest->GetImageStatus(&loadStatus);
      }

      if (loadStatus & imgIRequest::STATUS_ERROR || !imgCon) {
        // No image yet, or image load failed. Draw the alt-text and an icon
        // indicating the status (unless image is blocked, in which case we show nothing)

        PRInt16 imageStatus = nsIContentPolicy::ACCEPT;
        if (imageLoader) {
          imageLoader->GetImageBlockingStatus(&imageStatus);
        }
      
        if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer &&
            (NS_CP_ACCEPTED(imageStatus) ||
             imageStatus != nsIContentPolicy::REJECT_SERVER)) {
          DisplayAltFeedback(aPresContext, aRenderingContext, 
                             (loadStatus & imgIRequest::STATUS_ERROR)
                             ? gIconLoad->mBrokenImage
                             : gIconLoad->mLoadingImage);
        }
      }
      else {
        if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && imgCon) {
          // Render the image into our content area (the area inside
          // the borders and padding)
          nsRect inner = GetInnerArea();
          nsRect paintArea(inner);

          nscoord offsetY = 0; 

          // if the image is split account for y-offset
          if (mPrevInFlow) {
            offsetY = GetContinuationOffset();
          }

          if (mIntrinsicSize == mComputedSize) {
            // Find the actual rect to be painted to in the rendering context
            paintArea.IntersectRect(paintArea, aDirtyRect);

            // Rect in the image to paint
            nsRect r(paintArea.x - inner.x,
                     paintArea.y - inner.y + offsetY,
                     paintArea.width,
                     paintArea.height);
          
            aRenderingContext.DrawImage(imgCon, r, paintArea);
          } else {
            // The computed size is the total size of all the continuations,
            // including ourselves.  Note that we're basically inverting
            // mTransform here (would it too much to ask for
            // nsTransform2D::Invert?), since we need to convert from
            // rendering context coords to image coords...
            nsTransform2D trans;
            trans.SetToScale((float(mIntrinsicSize.width) / float(mComputedSize.width)),
                             (float(mIntrinsicSize.height) / float(mComputedSize.height)));
          
            // XXXbz it looks like we should take
            // IntersectRect(paintArea, aDirtyRect) here too, but things
            // get very weird if I do that ....
            //   paintArea.IntersectRect(paintArea, aDirtyRect);
          
            // dirty rect in image our coord size...
            nsRect r(paintArea.x - inner.x,
                     paintArea.y - inner.y + offsetY,
                     paintArea.width,
                     paintArea.height);

            // Transform that to image coords
            trans.TransformCoord(&r.x, &r.y, &r.width, &r.height);
          
#ifdef DEBUG_decode
            printf("IF draw src (%d,%d,%d,%d) -> dst (%d,%d,%d,%d)\n",
                   r.x, r.y, r.width, r.height, paintArea.x, paintArea.y,
                   paintArea.width, paintArea.height);
#endif

            aRenderingContext.DrawImage(imgCon, r, paintArea);
          }
        }

        nsImageMap* map = GetImageMap(aPresContext);
        if (nsnull != map) {
          nsRect inner = GetInnerArea();
          aRenderingContext.PushState();
          aRenderingContext.SetColor(NS_RGB(0, 0, 0));
          aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
          aRenderingContext.Translate(inner.x, inner.y);
          map->Draw(aPresContext, aRenderingContext);
          aRenderingContext.PopState();
        }

#ifdef DEBUG
        if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
            GetShowFrameBorders()) {
          nsImageMap* map = GetImageMap(aPresContext);
          if (nsnull != map) {
            nsRect inner = GetInnerArea();
            aRenderingContext.SetColor(NS_RGB(0, 0, 0));
            aRenderingContext.PushState();
            aRenderingContext.Translate(inner.x, inner.y);
            map->Draw(aPresContext, aRenderingContext);
            aRenderingContext.PopState();
          }
        }
#endif
      }
    }
  }
  PRInt16 displaySelection = 0;

  nsresult result; 
  result = aPresContext->PresShell()->GetSelectionFlags(&displaySelection);
  if (NS_FAILED(result))
    return result;
  if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES))
    return NS_OK;//no need to check the blue border, we cannot be drawn selected
//insert hook here for image selection drawing
#if IMAGE_EDITOR_CHECK
  //check to see if this frame is in an editor context
  //isEditor check. this needs to be changed to have better way to check
  if (displaySelection == nsISelectionDisplay::DISPLAY_ALL) 
  {
    nsCOMPtr<nsISelectionController> selCon;
    result = GetSelectionController(aPresContext, getter_AddRefs(selCon));
    if (NS_SUCCEEDED(result) && selCon)
    {
      nsCOMPtr<nsISelection> selection;
      result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
      if (NS_SUCCEEDED(result) && selection)
      {
        PRInt32 rangeCount;
        selection->GetRangeCount(&rangeCount);
        if (rangeCount == 1) //if not one then let code drop to nsFrame::Paint
        {
          nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
          if (parentContent)
          {
            PRInt32 thisOffset = parentContent->IndexOf(mContent);
            nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(parentContent);
            nsCOMPtr<nsIDOMNode> rangeNode;
            PRInt32 rangeOffset;
            nsCOMPtr<nsIDOMRange> range;
            selection->GetRangeAt(0,getter_AddRefs(range));
            if (range)
            {
              range->GetStartContainer(getter_AddRefs(rangeNode));
              range->GetStartOffset(&rangeOffset);

              if (parentNode && rangeNode && (rangeNode == parentNode) && rangeOffset == thisOffset)
              {
                range->GetEndContainer(getter_AddRefs(rangeNode));
                range->GetEndOffset(&rangeOffset);
                if ((rangeNode == parentNode) && (rangeOffset == (thisOffset +1))) //+1 since that would mean this whole content is selected only
                  return NS_OK; //do not allow nsFrame do draw any further selection
              }
            }
          }
        }
      }
    }
  }
#endif
  
  return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, nsISelectionDisplay::DISPLAY_IMAGES);
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageFrame::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)

Definition at line 199 of file nsImageFrame.cpp.

{
  NS_ENSURE_ARG_POINTER(aInstancePtr);
  *aInstancePtr = nsnull;

#ifdef DEBUG
  if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
    *aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
    return NS_OK;
  }
#endif

  if (aIID.Equals(NS_GET_IID(nsIImageFrame))) {
    *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
    return NS_OK;
  } else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
    *aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
    return NS_OK;
  } else if (aIID.Equals(NS_GET_IID(nsISupports))) {
    *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
    return NS_OK;
  }

  return NS_NOINTERFACE;
}

Here is the call graph for this function:

This function will recalculate mTransform.

If a non-null image is passed in, mIntrinsicSize will be recalculated from the image size. Otherwise, mIntrinsicSize will not be touched.

Returns:
PR_TRUE if aImage is non-null and its size did not match our previous intrinsic size
PR_FALSE otherwise

Definition at line 333 of file nsImageFrame.cpp.

{
  PRBool intrinsicSizeChanged = PR_FALSE;
  
  if (aImage) {
    float p2t;
    p2t = GetPresContext()->PixelsToTwips();

    nsSize imageSizeInPx;
    aImage->GetWidth(&imageSizeInPx.width);
    aImage->GetHeight(&imageSizeInPx.height);
    nsSize newSize(NSIntPixelsToTwips(imageSizeInPx.width, p2t),
                   NSIntPixelsToTwips(imageSizeInPx.height, p2t));
    if (mIntrinsicSize != newSize) {
      intrinsicSizeChanged = PR_TRUE;
      mIntrinsicSize = newSize;
    }
  }

  // In any case, we need to translate this over appropriately.  Set
  // translation _before_ setting scaling so that it does not get
  // scaled!

  // XXXbz does this introduce rounding errors because of the cast to
  // float?  Should we just manually add that stuff in every time
  // instead?
  mTransform.SetToTranslate(float(mBorderPadding.left),
                            float(mBorderPadding.top - GetContinuationOffset()));
  
  // Set the scale factors
  if (mIntrinsicSize.width != 0 && mIntrinsicSize.height != 0 &&
      mIntrinsicSize != mComputedSize) {
    mTransform.AddScale(float(mComputedSize.width)  / float(mIntrinsicSize.width),
                        float(mComputedSize.height) / float(mIntrinsicSize.height));
  }

  return intrinsicSizeChanged;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsImageFrame::Reflow ( nsPresContext aPresContext,
nsHTMLReflowMetrics aDesiredSize,
const nsHTMLReflowState aReflowState,
nsReflowStatus aStatus 
)

Definition at line 960 of file nsImageFrame.cpp.

{
  DO_GLOBAL_REFLOW_COUNT("nsImageFrame", aReflowState.reason);
  DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
  NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
                  ("enter nsImageFrame::Reflow: availSize=%d,%d",
                  aReflowState.availableWidth, aReflowState.availableHeight));

  NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");

  aStatus = NS_FRAME_COMPLETE;

  // see if we have a frozen size (i.e. a fixed width and height)
  if (HaveFixedSize(aReflowState)) {
    mState |= IMAGE_SIZECONSTRAINED;
  } else {
    mState &= ~IMAGE_SIZECONSTRAINED;
  }

  if (aReflowState.reason == eReflowReason_Initial) {
    mState |= IMAGE_GOTINITIALREFLOW;
  }

  // Set our borderpadding so that if GetDesiredSize has to recalc the
  // transform it can.
  mBorderPadding   = aReflowState.mComputedBorderPadding;

  // get the desired size of the complete image
  GetDesiredSize(aPresContext, aReflowState, aMetrics);

  // add borders and padding
  aMetrics.width  += mBorderPadding.left + mBorderPadding.right;
  aMetrics.height += mBorderPadding.top + mBorderPadding.bottom;
  
  if (mPrevInFlow) {
    nscoord y = GetContinuationOffset(&aMetrics.width);
    aMetrics.height -= y + mBorderPadding.top;
    aMetrics.height = PR_MAX(0, aMetrics.height);
  }


  // we have to split images if we are:
  //  in Paginated mode, we need to have a constrained height, and have a height larger than our available height
  PRUint32 loadStatus = imgIRequest::STATUS_NONE;
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
  NS_ASSERTION(imageLoader, "No content node??");
  if (imageLoader) {
    nsCOMPtr<imgIRequest> currentRequest;
    imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                            getter_AddRefs(currentRequest));
    if (currentRequest) {
      currentRequest->GetImageStatus(&loadStatus);
    }
  }
  if (aPresContext->IsPaginated() &&
      ((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || (mState & IMAGE_SIZECONSTRAINED)) &&
      NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight && 
      aMetrics.height > aReflowState.availableHeight) { 
    // split an image frame but not an image control frame
    if (nsLayoutAtoms::imageFrame == GetType()) {
      // our desired height was greater than 0, so to avoid infinite splitting, use 1 pixel as the min
      aMetrics.height = PR_MAX(NSToCoordRound(aPresContext->ScaledPixelsToTwips()), aReflowState.availableHeight);
      aStatus = NS_FRAME_NOT_COMPLETE;
    }
  }
  aMetrics.ascent  = aMetrics.height;
  aMetrics.descent = 0;

  if (aMetrics.mComputeMEW) {
    aMetrics.SetMEWToActualWidth(aReflowState.mStylePosition->mWidth.GetUnit());
  }
  
  if (aMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
    aMetrics.mMaximumWidth = aMetrics.width;
  }
  aMetrics.mOverflowArea.SetRect(0, 0, aMetrics.width, aMetrics.height);
  FinishAndStoreOverflow(&aMetrics);

  // Now that that's all done, check whether we're resizing... if we are,
  // invalidate our rect.
  // XXXbz we really only want to do this when reflow is completely done, but
  // we have no way to detect when mRect changes (since SetRect is non-virtual,
  // so this is the best we can do).
  if (mRect.width != aMetrics.width || mRect.height != aMetrics.height) {
    Invalidate(nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);
  }

  NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
                  ("exit nsImageFrame::Reflow: size=%d,%d",
                  aMetrics.width, aMetrics.height));
  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
  return NS_OK;
}

Here is the call graph for this function:

static void nsImageFrame::ReleaseGlobals ( ) [inline, static]

Definition at line 137 of file nsImageFrame.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Function to convert a dirty rect in the source image to a dirty rect for the image frame.

Definition at line 420 of file nsImageFrame.cpp.

{
  float p2t = GetPresContext()->PixelsToTwips();

  // When scaling the image, row N of the source image may (depending on
  // the scaling function) be used to draw any row in the destination image
  // between floor(F * (N-1)) and ceil(F * (N+1)), where F is the
  // floating-point scaling factor.  The same holds true for columns.
  // So, we start by computing that bound without the floor and ceiling.

  nsRect r(NSIntPixelsToTwips(aRect.x - 1, p2t),
           NSIntPixelsToTwips(aRect.y - 1, p2t),
           NSIntPixelsToTwips(aRect.width + 2, p2t),
           NSIntPixelsToTwips(aRect.height + 2, p2t));

  mTransform.TransformCoord(&r.x, &r.y, &r.width, &r.height);

  // Now, round the edges out to the pixel boundary.
  int scale = (int) p2t;
  nscoord right = r.x + r.width;
  nscoord bottom = r.y + r.height;

  r.x -= (scale + (r.x % scale)) % scale;
  r.y -= (scale + (r.y % scale)) % scale;
  r.width = right + ((scale - (right % scale)) % scale) - r.x;
  r.height = bottom + ((scale - (bottom % scale)) % scale) - r.y;

  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::SpecToURI ( const nsAString &  aSpec,
nsIIOService aIOService,
nsIURI **  aURI 
) [inline, private]

Definition at line 1905 of file nsImageFrame.cpp.

{
  nsCOMPtr<nsIURI> baseURI;
  if (mContent) {
    baseURI = mContent->GetBaseURI();
  }
  nsCAutoString charset;
  GetDocumentCharacterSet(charset);
  NS_NewURI(aURI, aSpec, 
            charset.IsEmpty() ? nsnull : charset.get(), 
            baseURI, aIOService);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::TranslateEventCoords ( const nsPoint aPoint,
nsPoint aResult 
) [protected]

Definition at line 1583 of file nsImageFrame.cpp.

{
  nscoord x = aPoint.x;
  nscoord y = aPoint.y;

  // If we have a view then the event coordinates are already relative
  // to this frame; otherwise we have to adjust the coordinates
  // appropriately.
  if (!HasView()) {
    nsPoint offset;
    nsIView *view;
    GetOffsetFromView(offset, &view);
    if (nsnull != view) {
      x -= offset.x;
      y -= offset.y;
    }
  }

  // Subtract out border and padding here so that the coordinates are
  // now relative to the content area of this frame.
  nsRect inner = GetInnerArea();
  x -= inner.x;
  y -= inner.y;

  // Translate the coordinates from twips to pixels
  float t2p;
  t2p = GetPresContext()->TwipsToPixels();
  aResult.x = NSTwipsToIntPixels(x, t2p);
  aResult.y = NSTwipsToIntPixels(y, t2p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageFrame::TriggerLink ( nsPresContext aPresContext,
nsIURI aURI,
const nsString aTargetSpec,
PRBool  aClick 
) [protected]

Definition at line 1527 of file nsImageFrame.cpp.

{
  // We get here with server side image map
  nsILinkHandler *handler = aPresContext->GetLinkHandler();
  if (handler) {
    if (aClick) {
      // Check that this page is allowed to load this URI.
      // Almost a copy of the similarly named method in nsGenericElement
      nsresult rv;
      nsCOMPtr<nsIScriptSecurityManager> securityManager = 
               do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);

      if (NS_FAILED(rv))
        return;

      nsIPresShell *ps = aPresContext->GetPresShell();
      if (!ps)
        return;

      nsIDocument *doc = ps->GetDocument();
      if (doc) {
        rv = securityManager->
          CheckLoadURIWithPrincipal(doc->GetPrincipal(), aURI,
                                    nsIScriptSecurityManager::STANDARD);

        // Only pass off the click event if the script security manager
        // says it's ok.
        if (NS_SUCCEEDED(rv))
          handler->OnLinkClick(mContent, eLinkVerb_Replace, aURI,
                               aTargetSpec.get());
      }
    }
    else {
      handler->OnOverLink(mContent, aURI, aTargetSpec.get());
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsImageListener [friend]

Definition at line 188 of file nsImageFrame.h.


Member Data Documentation

Definition at line 306 of file nsImageFrame.h.

Definition at line 251 of file nsImageFrame.h.

Definition at line 247 of file nsImageFrame.h.

Definition at line 243 of file nsImageFrame.h.

Definition at line 248 of file nsImageFrame.h.

Definition at line 245 of file nsImageFrame.h.

nsTransform2D nsImageFrame::mTransform [private]

Definition at line 249 of file nsImageFrame.h.

Definition at line 253 of file nsImageFrame.h.


The documentation for this class was generated from the following files: