mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
new
This commit is contained in:
parent
3f4e33030c
commit
bdc62f7dd6
113
layout/generic/nsImageFrame.h
Normal file
113
layout/generic/nsImageFrame.h
Normal file
@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsImageFrame_h___
|
||||
#define nsImageFrame_h___
|
||||
|
||||
#include "nsLeafFrame.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsHTMLImageLoader.h"
|
||||
|
||||
class nsIFrame;
|
||||
class nsImageMap;
|
||||
class nsIImage;
|
||||
class nsIURL;
|
||||
struct nsHTMLReflowState;
|
||||
struct nsHTMLReflowMetrics;
|
||||
struct nsSize;
|
||||
|
||||
#define ImageFrameSuper nsLeafFrame
|
||||
|
||||
class nsImageFrame : public ImageFrameSuper {
|
||||
public:
|
||||
NS_IMETHOD DeleteFrame(nsIPresContext& aPresContext);
|
||||
NS_IMETHOD Init(nsIPresContext& aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParent,
|
||||
nsIStyleContext* aContext,
|
||||
nsIFrame* aPrevInFlow);
|
||||
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect,
|
||||
nsFramePaintLayer aWhichLayer);
|
||||
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
NS_METHOD HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
|
||||
nsPoint& aPoint,
|
||||
PRInt32& aCursor);
|
||||
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
||||
nsIContent* aChild,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint);
|
||||
|
||||
protected:
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize);
|
||||
|
||||
nsresult UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus);
|
||||
|
||||
nsImageMap* GetImageMap();
|
||||
|
||||
void TriggerLink(nsIPresContext& aPresContext,
|
||||
const nsString& aURLSpec,
|
||||
const nsString& aTargetSpec,
|
||||
PRBool aClick);
|
||||
|
||||
PRBool IsServerImageMap();
|
||||
|
||||
PRIntn GetSuppress();
|
||||
|
||||
void MeasureString(const PRUnichar* aString,
|
||||
PRInt32 aLength,
|
||||
nscoord aMaxWidth,
|
||||
PRUint32& aMaxFit,
|
||||
nsIRenderingContext& aContext);
|
||||
|
||||
void DisplayAltText(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
const nsString& aAltText,
|
||||
const nsRect& aRect);
|
||||
|
||||
void DisplayAltFeedback(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
PRInt32 aIconId);
|
||||
|
||||
void GetInnerArea(nsIPresContext* aPresContext,
|
||||
nsRect& aInnerArea) const;
|
||||
|
||||
static nsresult UpdateImageFrame(nsIPresContext* aPresContext,
|
||||
nsHTMLImageLoader* aLoader,
|
||||
nsIFrame* aFrame,
|
||||
void* aClosure,
|
||||
PRUint32 aStatus);
|
||||
|
||||
nsHTMLImageLoader mImageLoader;
|
||||
nsImageMap* mImageMap;
|
||||
PRBool mSizeFrozen;
|
||||
nsMargin mBorderPadding;
|
||||
};
|
||||
|
||||
#endif /* nsImageFrame_h___ */
|
430
layout/html/base/src/nsHTMLImageLoader.cpp
Normal file
430
layout/html/base/src/nsHTMLImageLoader.cpp
Normal file
@ -0,0 +1,430 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "nsHTMLImageLoader.h"
|
||||
#include "nsIHTMLReflow.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsIURL.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#undef NOISY_IMAGE_LOADING
|
||||
#else
|
||||
#undef NOISY_IMAGE_LOADING
|
||||
#endif
|
||||
|
||||
// XXX todo:
|
||||
// - test dom src= width= height=
|
||||
// - test dom thrashing image dimensions and src's
|
||||
// - test dom creating/destroying new IMG's
|
||||
// - make sure frozen image size is only sticky for src= changes not
|
||||
// for subsequent width/height= changes
|
||||
// - test aspect images
|
||||
// - test aspect w/dom src= width= height=
|
||||
// - free up dead image loaders in nsPresContext
|
||||
// - test bad image urls
|
||||
// - test alternate content
|
||||
// - % widths inside tables
|
||||
// - image bullets
|
||||
// - dom stuff
|
||||
// - bad image urls
|
||||
|
||||
nsHTMLImageLoader::nsHTMLImageLoader()
|
||||
: mBaseURL(nsnull),
|
||||
mFrame(nsnull),
|
||||
mCallBack(nsnull),
|
||||
mClosure(nsnull),
|
||||
mImageLoader(nsnull),
|
||||
mLoadImageFailed(PR_FALSE),
|
||||
mHaveIntrinsicImageSize(PR_FALSE),
|
||||
mNeedIntrinsicImageSize(PR_FALSE),
|
||||
mHaveComputedSize(PR_FALSE),
|
||||
mIntrinsicImageSize(0, 0),
|
||||
mComputedImageSize(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLImageLoader::~nsHTMLImageLoader()
|
||||
{
|
||||
NS_IF_RELEASE(mBaseURL);
|
||||
NS_IF_RELEASE(mImageLoader);
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::Init(nsIFrame* aFrame,
|
||||
nsHTMLImageLoaderCB aCallBack,
|
||||
void* aClosure,
|
||||
nsIURL* aBaseURL,
|
||||
const nsString& aURLSpec)
|
||||
{
|
||||
mFrame = aFrame;
|
||||
mCallBack = aCallBack;
|
||||
mClosure = aClosure;
|
||||
mBaseURL = aBaseURL;
|
||||
NS_IF_ADDREF(mBaseURL);
|
||||
SetURL(aURLSpec);
|
||||
}
|
||||
|
||||
nsIImage*
|
||||
nsHTMLImageLoader::GetImage()
|
||||
{
|
||||
nsIImage* image = nsnull;
|
||||
if (mImageLoader) {
|
||||
mImageLoader->GetImage(&image);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::SetURL(const nsString& aNewSpec)
|
||||
{
|
||||
mURLSpec = aNewSpec;
|
||||
if (mBaseURL) {
|
||||
nsString empty;
|
||||
nsresult rv = NS_MakeAbsoluteURL(mBaseURL, empty, mURLSpec, mURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
mURL = mURLSpec;
|
||||
}
|
||||
} else {
|
||||
mURL = mURLSpec;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::StopLoadImage(nsIPresContext* aPresContext)
|
||||
{
|
||||
if (mImageLoader) {
|
||||
aPresContext->StopLoadImage(mFrame, mImageLoader);
|
||||
NS_RELEASE(mImageLoader);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::StopAllLoadImages(nsIPresContext* aPresContext)
|
||||
{
|
||||
aPresContext->StopAllLoadImagesFor(mFrame);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLImageLoader::ImageLoadCB(nsIPresContext* aPresContext,
|
||||
nsIFrameImageLoader* aLoader,
|
||||
nsIFrame* aFrame,
|
||||
void* aClosure,
|
||||
PRUint32 aStatus)
|
||||
{
|
||||
if (aClosure) {
|
||||
((nsHTMLImageLoader*)aClosure)->Update(aPresContext, aFrame, aStatus);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::Update(nsIPresContext* aPresContext,
|
||||
nsIFrame* aFrame,
|
||||
PRUint32 aStatus)
|
||||
{
|
||||
#ifdef NOISY_IMAGE_LOADING
|
||||
nsFrame::ListTag(stdout, aFrame);
|
||||
printf(": update: status=%x [loader=%p]\n", aStatus, mImageLoader);
|
||||
#endif
|
||||
if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
|
||||
if (mImageLoader) {
|
||||
mImageLoader->GetSize(mIntrinsicImageSize);
|
||||
if (mNeedIntrinsicImageSize) {
|
||||
mHaveIntrinsicImageSize = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pass on update to the user of this object if they want it
|
||||
if (mCallBack) {
|
||||
(*mCallBack)(aPresContext, this, aFrame, mClosure, aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext)
|
||||
{
|
||||
if (!mFrame) {
|
||||
// We were not initialized!
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// This is kind of sick, but its possible that we will get a
|
||||
// notification *before* we have setup mImageLoader. To get around
|
||||
// this, we let the pres-context store into mImageLoader and sort
|
||||
// things after it returns.
|
||||
nsIFrameImageLoader* oldLoader = mImageLoader;
|
||||
nsresult rv = aPresContext->StartLoadImage(mURL, nsnull,
|
||||
(mNeedIntrinsicImageSize
|
||||
? nsnull
|
||||
: &mComputedImageSize),
|
||||
mFrame, ImageLoadCB, (void*)this,
|
||||
&mImageLoader);
|
||||
#ifdef NOISY_IMAGE_LOADING
|
||||
nsFrame::ListTag(stdout, mFrame);
|
||||
printf(": loading image '");
|
||||
fputs(mURL, stdout);
|
||||
printf("' @ ");
|
||||
if (mNeedIntrinsicImageSize) {
|
||||
printf("intrinsic size ");
|
||||
}
|
||||
printf("%d,%d; oldLoader=%p newLoader=%p\n",
|
||||
mComputedImageSize.width, mComputedImageSize.height,
|
||||
oldLoader, mImageLoader);
|
||||
#endif
|
||||
|
||||
if (oldLoader != mImageLoader) {
|
||||
if (nsnull != oldLoader) {
|
||||
// Tell presentation context we are done with the old image loader
|
||||
aPresContext->StopLoadImage(mFrame, oldLoader);
|
||||
}
|
||||
}
|
||||
|
||||
// Release the old image loader
|
||||
NS_IF_RELEASE(oldLoader);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::UpdateURLSpec(nsIPresContext* aPresContext,
|
||||
const nsString& aNewSpec)
|
||||
{
|
||||
SetURL(aNewSpec);
|
||||
|
||||
// Start image loading with the previously computed size information
|
||||
StartLoadImage(aPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
const nsHTMLReflowState* aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize)
|
||||
{
|
||||
nscoord widthConstraint = NS_INTRINSICSIZE;
|
||||
nscoord heightConstraint = NS_INTRINSICSIZE;
|
||||
PRBool fixedContentWidth = PR_FALSE;
|
||||
PRBool fixedContentHeight = PR_FALSE;
|
||||
|
||||
if (aReflowState) {
|
||||
widthConstraint = aReflowState->computedWidth;
|
||||
heightConstraint = aReflowState->computedHeight;
|
||||
|
||||
// Determine whether the image has fixed content width and height
|
||||
fixedContentWidth = aReflowState->HaveFixedContentWidth();
|
||||
fixedContentHeight = aReflowState->HaveFixedContentHeight();
|
||||
if (NS_INTRINSICSIZE == widthConstraint) {
|
||||
fixedContentWidth = PR_FALSE;
|
||||
}
|
||||
if (NS_INTRINSICSIZE == heightConstraint) {
|
||||
fixedContentHeight = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool haveComputedSize = PR_FALSE;
|
||||
PRBool needIntrinsicImageSize = PR_FALSE;
|
||||
nscoord newWidth, newHeight;
|
||||
if (fixedContentWidth) {
|
||||
if (fixedContentHeight) {
|
||||
newWidth = widthConstraint;
|
||||
newHeight = heightConstraint;
|
||||
haveComputedSize = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
// We have a width, and an auto height. Compute height from
|
||||
// width once we have the intrinsic image size.
|
||||
newWidth = widthConstraint;
|
||||
if (mHaveIntrinsicImageSize) {
|
||||
float width = mIntrinsicImageSize.width
|
||||
? mIntrinsicImageSize.width
|
||||
: mIntrinsicImageSize.height; // avoid divide by zero
|
||||
float height = mIntrinsicImageSize.height;
|
||||
newHeight = (nscoord)
|
||||
NSToIntRound(widthConstraint * height / width);
|
||||
haveComputedSize = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
newHeight = 1;
|
||||
needIntrinsicImageSize = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fixedContentHeight) {
|
||||
// We have a height, and an auto width. Compute width from height
|
||||
// once we have the intrinsic image size.
|
||||
newHeight = heightConstraint;
|
||||
if (mHaveIntrinsicImageSize) {
|
||||
float width = mIntrinsicImageSize.width;
|
||||
float height = mIntrinsicImageSize.height
|
||||
? mIntrinsicImageSize.height
|
||||
: mIntrinsicImageSize.width; // avoid divide by zero
|
||||
newWidth = (nscoord)
|
||||
NSToIntRound(heightConstraint * width / height);
|
||||
haveComputedSize = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
newWidth = 1;
|
||||
needIntrinsicImageSize = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (mHaveIntrinsicImageSize) {
|
||||
newWidth = mIntrinsicImageSize.width;
|
||||
newHeight = mIntrinsicImageSize.height;
|
||||
haveComputedSize = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
newWidth = 1;
|
||||
newHeight = 1;
|
||||
needIntrinsicImageSize = PR_TRUE;
|
||||
}
|
||||
}
|
||||
mNeedIntrinsicImageSize = needIntrinsicImageSize;
|
||||
mHaveComputedSize = haveComputedSize;
|
||||
mComputedImageSize.width = newWidth;
|
||||
mComputedImageSize.height = newHeight;
|
||||
#ifdef NOISY_IMAGE_LOADING
|
||||
nsFrame::ListTag(stdout, mFrame);
|
||||
printf(": %s%scomputedSize=%d,%d\n",
|
||||
mNeedIntrinsicImageSize ? "need-instrinsic-size " : "",
|
||||
mHaveComputedSize ? "have-computed-size " : "",
|
||||
mComputedImageSize.width, mComputedImageSize.height);
|
||||
#endif
|
||||
|
||||
// Load the image at the desired size
|
||||
StartLoadImage(aPresContext);
|
||||
|
||||
aDesiredSize.width = mComputedImageSize.width;
|
||||
aDesiredSize.height = mComputedImageSize.height;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLImageLoader::GetLoadImageFailed() const
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
if (nsnull != mImageLoader) {
|
||||
// Ask the image loader whether the load failed
|
||||
PRUint32 loadStatus;
|
||||
mImageLoader->GetImageLoadStatus(&loadStatus);
|
||||
result = 0 != (loadStatus & NS_IMAGE_LOAD_STATUS_ERROR);
|
||||
}
|
||||
|
||||
result |= PRBool(mLoadImageFailed);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
nsHTMLImageLoader::GetLoadStatus() const
|
||||
{
|
||||
PRUint32 loadStatus = NS_IMAGE_LOAD_STATUS_NONE;
|
||||
if (mImageLoader) {
|
||||
mImageLoader->GetImageLoadStatus(&loadStatus);
|
||||
}
|
||||
return loadStatus;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult
|
||||
nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
|
||||
const nsSize* aDesiredSize)
|
||||
{
|
||||
aLoadStatus = NS_IMAGE_LOAD_STATUS_NONE;
|
||||
|
||||
// Get absolute url the first time through
|
||||
nsresult rv;
|
||||
nsAutoString src;
|
||||
#ifdef _WIN32
|
||||
if (mLoadImageFailed) {
|
||||
// We've already notified the pres shell that we're unable to render
|
||||
// the image so just return
|
||||
return NS_OK;
|
||||
} else if (nsnull == mURLSpec) {
|
||||
// No URI was specified for the src. Indicate we're unable to load the
|
||||
// image and notify the pres shell
|
||||
|
||||
// XXX this is in the wrong spot... the policy should be in the user
|
||||
// of this class, not here
|
||||
mLoadImageFailed = PR_TRUE;
|
||||
nsIPresShell* presShell;
|
||||
aPresContext->GetShell(&presShell);
|
||||
presShell->CantRenderReplacedElement(aPresContext, aTargetFrame);
|
||||
NS_RELEASE(presShell);
|
||||
return NS_OK;
|
||||
#else
|
||||
if (mLoadImageFailed || (nsnull == mURLSpec)) {
|
||||
src.Append(BROKEN_IMAGE_URL);
|
||||
#endif
|
||||
} else if (nsnull == mImageLoader) {
|
||||
// Create an absolute URL
|
||||
if (mBaseURL) {
|
||||
nsString empty;
|
||||
nsresult rv = NS_MakeAbsoluteURL(mBaseURL, empty, *mURLSpec, src);
|
||||
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
// Just use the URL spec
|
||||
src = *mURLSpec;
|
||||
}
|
||||
}
|
||||
|
||||
if (nsnull == mImageLoader) {
|
||||
// Start image loading. Note that we don't specify a background color
|
||||
// so transparent images are always rendered using a transparency mask
|
||||
#ifdef NOISY_IMAGE_LOADING
|
||||
nsFrame::ListTag(stdout, aTargetFrame);
|
||||
printf(": loading ");
|
||||
fputs(*mURLSpec, stdout);
|
||||
printf(" at %d,%d size\n",
|
||||
mComputedImageSize.width, mComputedImageSize.height);
|
||||
#endif
|
||||
nsSize zero(0, 0);
|
||||
rv = aPresContext->StartLoadImage(src, nsnull, aTargetFrame,
|
||||
(mNeedIntrinsicImageSize
|
||||
? zero
|
||||
: mComputedImageSize),
|
||||
aCallBack, PR_TRUE,
|
||||
PR_TRUE, &mImageLoader);
|
||||
if ((NS_OK != rv) || (nsnull == mImageLoader)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Examine current image load status
|
||||
mImageLoader->GetImageLoadStatus(aLoadStatus);
|
||||
if (0 != (aLoadStatus & NS_IMAGE_LOAD_STATUS_ERROR)) {
|
||||
NS_RELEASE(mImageLoader);
|
||||
#ifdef _WIN32
|
||||
// Display broken icon along with alt-text
|
||||
mLoadImageFailed = PR_TRUE;
|
||||
#else
|
||||
if (mLoadImageFailed) {
|
||||
// We are doomed. Loading the broken image has just failed.
|
||||
mLoadBrokenImageFailed = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
// Try again, this time using the broke-image url
|
||||
mLoadImageFailed = PR_TRUE;
|
||||
return StartLoadImage(aPresContext, aTargetFrame, nsnull, aLoadStatus);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
119
layout/html/base/src/nsHTMLImageLoader.h
Normal file
119
layout/html/base/src/nsHTMLImageLoader.h
Normal file
@ -0,0 +1,119 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsHTMLImageLoader_h___
|
||||
#define nsHTMLImageLoader_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIPresContext.h"
|
||||
|
||||
class nsIFrame;
|
||||
class nsImageMap;
|
||||
class nsIImage;
|
||||
class nsIURL;
|
||||
struct nsHTMLReflowState;
|
||||
struct nsHTMLReflowMetrics;
|
||||
struct nsSize;
|
||||
|
||||
class nsHTMLImageLoader;
|
||||
typedef nsresult (*nsHTMLImageLoaderCB)(nsIPresContext* aPresContext,
|
||||
nsHTMLImageLoader* aLoader,
|
||||
nsIFrame* aFrame,
|
||||
void* aClosure,
|
||||
PRUint32 aStatus);
|
||||
|
||||
/**
|
||||
* HTML image loader. This is designed to encapsulate the loading
|
||||
* and sizing process of html images (basically so that the logic
|
||||
* can be reused in the image button form control code and the html
|
||||
* image layout code).
|
||||
*/
|
||||
class nsHTMLImageLoader {
|
||||
public:
|
||||
nsHTMLImageLoader();
|
||||
~nsHTMLImageLoader();
|
||||
|
||||
void Init(nsIFrame* aFrame, nsHTMLImageLoaderCB aCallBack, void* aClosure,
|
||||
nsIURL* aBaseURL, const nsString& aURLSpec);
|
||||
|
||||
nsIImage* GetImage();
|
||||
|
||||
void GetURLSpec(nsString& aResult) {
|
||||
aResult = mURLSpec;
|
||||
}
|
||||
|
||||
void UpdateURLSpec(nsIPresContext* aPresContext,
|
||||
const nsString& aNewSpec);
|
||||
|
||||
// Stop the current image load request from loading
|
||||
void StopLoadImage(nsIPresContext* aPresContext);
|
||||
|
||||
// Stop all image load requests from loading
|
||||
void StopAllLoadImages(nsIPresContext* aPresContext);
|
||||
|
||||
// Get the desired size for the image. If aReflowState is not null
|
||||
// then the image will be scaled to fit the reflow
|
||||
// constraints. Otherwise, the image will be left at its intrinsic
|
||||
// size.
|
||||
void GetDesiredSize(nsIPresContext* aPresContext,
|
||||
const nsHTMLReflowState* aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize);
|
||||
|
||||
PRUint32 GetLoadStatus() const;
|
||||
|
||||
PRBool GetLoadImageFailed() const;
|
||||
|
||||
PRBool IsImageSizeKnown() const {
|
||||
return mHaveComputedSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
static nsresult ImageLoadCB(nsIPresContext* aPresContext,
|
||||
nsIFrameImageLoader* aLoader,
|
||||
nsIFrame* aFrame,
|
||||
void* aClosure,
|
||||
PRUint32 aStatus);
|
||||
|
||||
void Update(nsIPresContext* aPresContext,
|
||||
nsIFrame* aFrame,
|
||||
PRUint32 aStatus);
|
||||
|
||||
void SetURL(const nsString& aNewSpec);
|
||||
|
||||
nsresult StartLoadImage(nsIPresContext* aPresContext);
|
||||
|
||||
nsIURL* mBaseURL;
|
||||
nsIFrame* mFrame;
|
||||
nsHTMLImageLoaderCB mCallBack;
|
||||
void* mClosure;
|
||||
|
||||
nsString mURLSpec;
|
||||
nsString mURL;
|
||||
|
||||
nsIFrameImageLoader* mImageLoader;
|
||||
|
||||
PRPackedBool mLoadImageFailed;
|
||||
PRPackedBool mHaveIntrinsicImageSize;
|
||||
PRPackedBool mNeedIntrinsicImageSize;
|
||||
PRPackedBool mHaveComputedSize;
|
||||
|
||||
nsSize mIntrinsicImageSize;
|
||||
nsSize mComputedImageSize;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLImageLoader_h___ */
|
113
layout/html/base/src/nsImageFrame.h
Normal file
113
layout/html/base/src/nsImageFrame.h
Normal file
@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsImageFrame_h___
|
||||
#define nsImageFrame_h___
|
||||
|
||||
#include "nsLeafFrame.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsHTMLImageLoader.h"
|
||||
|
||||
class nsIFrame;
|
||||
class nsImageMap;
|
||||
class nsIImage;
|
||||
class nsIURL;
|
||||
struct nsHTMLReflowState;
|
||||
struct nsHTMLReflowMetrics;
|
||||
struct nsSize;
|
||||
|
||||
#define ImageFrameSuper nsLeafFrame
|
||||
|
||||
class nsImageFrame : public ImageFrameSuper {
|
||||
public:
|
||||
NS_IMETHOD DeleteFrame(nsIPresContext& aPresContext);
|
||||
NS_IMETHOD Init(nsIPresContext& aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParent,
|
||||
nsIStyleContext* aContext,
|
||||
nsIFrame* aPrevInFlow);
|
||||
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect,
|
||||
nsFramePaintLayer aWhichLayer);
|
||||
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
NS_METHOD HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
|
||||
nsPoint& aPoint,
|
||||
PRInt32& aCursor);
|
||||
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
||||
nsIContent* aChild,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint);
|
||||
|
||||
protected:
|
||||
virtual ~nsImageFrame();
|
||||
|
||||
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize);
|
||||
|
||||
nsresult UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus);
|
||||
|
||||
nsImageMap* GetImageMap();
|
||||
|
||||
void TriggerLink(nsIPresContext& aPresContext,
|
||||
const nsString& aURLSpec,
|
||||
const nsString& aTargetSpec,
|
||||
PRBool aClick);
|
||||
|
||||
PRBool IsServerImageMap();
|
||||
|
||||
PRIntn GetSuppress();
|
||||
|
||||
void MeasureString(const PRUnichar* aString,
|
||||
PRInt32 aLength,
|
||||
nscoord aMaxWidth,
|
||||
PRUint32& aMaxFit,
|
||||
nsIRenderingContext& aContext);
|
||||
|
||||
void DisplayAltText(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
const nsString& aAltText,
|
||||
const nsRect& aRect);
|
||||
|
||||
void DisplayAltFeedback(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
PRInt32 aIconId);
|
||||
|
||||
void GetInnerArea(nsIPresContext* aPresContext,
|
||||
nsRect& aInnerArea) const;
|
||||
|
||||
static nsresult UpdateImageFrame(nsIPresContext* aPresContext,
|
||||
nsHTMLImageLoader* aLoader,
|
||||
nsIFrame* aFrame,
|
||||
void* aClosure,
|
||||
PRUint32 aStatus);
|
||||
|
||||
nsHTMLImageLoader mImageLoader;
|
||||
nsImageMap* mImageMap;
|
||||
PRBool mSizeFrozen;
|
||||
nsMargin mBorderPadding;
|
||||
};
|
||||
|
||||
#endif /* nsImageFrame_h___ */
|
Loading…
x
Reference in New Issue
Block a user