1998-09-09 02:34:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-09-09 02:34:40 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-09-09 02:34:40 +04:00
|
|
|
*/
|
|
|
|
#include "nsHTMLParts.h"
|
1999-07-08 23:38:08 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-14 01:51:20 +04:00
|
|
|
#include "nsImageFrame.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFrameImageLoader.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIHTMLAttributes.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1999-01-09 03:13:19 +03:00
|
|
|
#include "nsImageMap.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
1998-09-23 06:30:21 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsCSSRendering.h"
|
1999-07-08 23:38:08 +04:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
1998-09-20 04:08:24 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-12-20 04:21:23 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-06 02:02:27 +03:00
|
|
|
#include "nsTextFragment.h"
|
1999-01-30 04:04:35 +03:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
1999-02-04 20:03:46 +03:00
|
|
|
#include "nsIStyleSet.h"
|
1999-08-31 07:09:40 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-09-01 05:02:16 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
|
|
|
#include "nsIFrameManager.h"
|
2000-08-09 00:35:12 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
|
|
|
#else
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
1998-11-14 00:31:50 +03:00
|
|
|
#endif
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
|
|
|
|
|
|
|
|
// Value's for mSuppress
|
|
|
|
#define SUPPRESS_UNSET 0
|
|
|
|
#define DONT_SUPPRESS 1
|
|
|
|
#define SUPPRESS 2
|
|
|
|
#define DEFAULT_SUPPRESS 3
|
|
|
|
|
|
|
|
// Default alignment value (so we can tell an unset value from a set value)
|
|
|
|
#define ALIGN_UNSET PRUint8(-1)
|
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewImageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsImageFrame* it = new (aPresShell) nsImageFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
if (nsnull == it) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
nsImageFrame::nsImageFrame() :
|
|
|
|
mLowSrcImageLoader(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-04-19 18:00:11 +04:00
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
delete mLowSrcImageLoader;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::Destroy(nsIPresContext* aPresContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-08-12 04:38:22 +04:00
|
|
|
// 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);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Release image loader first so that it's refcnt can go to zero
|
1999-11-24 09:03:41 +03:00
|
|
|
mImageLoader.StopAllLoadImages(aPresContext);
|
2000-04-19 18:00:11 +04:00
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
mLowSrcImageLoader->StopAllLoadImages(aPresContext);
|
|
|
|
}
|
2000-08-12 04:38:22 +04:00
|
|
|
|
1999-07-22 06:24:52 +04:00
|
|
|
return nsLeafFrame::Destroy(aPresContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::Init(nsIPresContext* aPresContext,
|
1998-12-29 06:38:16 +03:00
|
|
|
nsIContent* aContent,
|
1999-01-14 08:16:23 +03:00
|
|
|
nsIFrame* aParent,
|
1999-02-25 06:27:57 +03:00
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1998-12-29 06:38:16 +03:00
|
|
|
{
|
1999-04-14 01:51:20 +04:00
|
|
|
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent,
|
|
|
|
aContext, aPrevInFlow);
|
1999-02-27 03:57:04 +03:00
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
// See if we have a SRC attribute
|
1999-01-15 04:57:58 +03:00
|
|
|
nsAutoString src;
|
1999-04-14 01:51:20 +04:00
|
|
|
nsresult ca;
|
|
|
|
ca = mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, src);
|
1999-05-06 03:40:21 +04:00
|
|
|
if ((NS_CONTENT_ATTR_HAS_VALUE != ca) || (src.Length() == 0))
|
|
|
|
{
|
|
|
|
// Let's see if this is an object tag and we have a DATA attribute
|
|
|
|
nsIAtom* tag;
|
|
|
|
mContent->GetTag(tag);
|
|
|
|
|
|
|
|
if(tag == nsHTMLAtoms::object)
|
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::data, src);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(tag);
|
1999-02-27 03:57:04 +03:00
|
|
|
}
|
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
nsAutoString lowSrc;
|
|
|
|
nsresult lowSrcResult;
|
|
|
|
lowSrcResult = mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::lowsrc, lowSrc);
|
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
// Set the image loader's source URL and base URL
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* baseURL = nsnull;
|
1999-04-24 00:00:14 +04:00
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
rv = mContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
htmlContent->GetBaseURL(baseURL);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIDocument* doc;
|
|
|
|
rv = mContent->GetDocument(doc);
|
1999-04-14 01:51:20 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-04-24 00:00:14 +04:00
|
|
|
doc->GetBaseURL(baseURL);
|
|
|
|
NS_RELEASE(doc);
|
1999-01-15 04:57:58 +03:00
|
|
|
}
|
1998-12-29 06:38:16 +03:00
|
|
|
}
|
2000-04-19 18:00:11 +04:00
|
|
|
|
2000-08-25 10:03:49 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == lowSrcResult && lowSrc.Length() > 0) {
|
2000-04-19 18:00:11 +04:00
|
|
|
mLowSrcImageLoader = new nsHTMLImageLoader;
|
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
mLowSrcImageLoader->Init(this, UpdateImageFrame, (void*)mLowSrcImageLoader, baseURL, lowSrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mImageLoader.Init(this, UpdateImageFrame, (void*)&mImageLoader, baseURL, src);
|
1999-04-24 00:00:14 +04:00
|
|
|
NS_IF_RELEASE(baseURL);
|
1998-12-29 06:38:16 +03:00
|
|
|
|
2000-04-01 04:13:51 +04:00
|
|
|
mInitialLoadCompleted = PR_FALSE;
|
2000-09-08 01:03:26 +04:00
|
|
|
mCanSendLoadEvent = PR_TRUE;
|
1998-12-29 06:38:16 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::UpdateImageFrame(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLImageLoader* aLoader,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
void* aClosure,
|
|
|
|
PRUint32 aStatus)
|
|
|
|
{
|
|
|
|
nsImageFrame* frame = (nsImageFrame*) aFrame;
|
2000-04-19 18:00:11 +04:00
|
|
|
return frame->UpdateImage(aPresContext, aStatus, aClosure);
|
1999-04-14 01:51:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-04-19 18:00:11 +04:00
|
|
|
nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void* aClosure)
|
1998-09-26 22:36:59 +04:00
|
|
|
{
|
1999-04-14 01:51:20 +04:00
|
|
|
#ifdef NOISY_IMAGE_LOADING
|
|
|
|
ListTag(stdout);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": UpdateImage: status=%x\n", aStatus);
|
1999-04-14 01:51:20 +04:00
|
|
|
#endif
|
2000-04-19 18:00:11 +04:00
|
|
|
|
2000-01-14 02:32:47 +03:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
2000-01-12 11:28:24 +03:00
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
// check to see if an image error occurred
|
|
|
|
PRBool imageFailedToLoad = PR_FALSE;
|
|
|
|
if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { // We failed to load the image. Notify the pres shell
|
|
|
|
|
|
|
|
// One of the two images didn't load, which one?
|
|
|
|
// see if we are loading the lowsrc image
|
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
// We ARE loading the lowsrc image
|
|
|
|
// check to see if the closure data is the lowsrc
|
|
|
|
if (aClosure == mLowSrcImageLoader) {
|
|
|
|
// The lowsrc failed to load, but only set the bool to true
|
|
|
|
// true if the src image failed.
|
2000-05-01 18:35:19 +04:00
|
|
|
imageFailedToLoad = mImageLoader.GetImage() == nsnull || (mImageLoader.GetLoadStatus() & NS_IMAGE_LOAD_STATUS_ERROR);
|
2000-04-19 18:00:11 +04:00
|
|
|
} else {
|
|
|
|
// src failed to load,
|
|
|
|
// see if the lowsrc is here so we can paint it instead
|
|
|
|
imageFailedToLoad = (mLowSrcImageLoader->GetLoadStatus() & NS_IMAGE_LOAD_STATUS_ERROR) != 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imageFailedToLoad = PR_TRUE;
|
1999-04-14 01:51:20 +04:00
|
|
|
}
|
1999-02-18 06:26:19 +03:00
|
|
|
}
|
2000-04-19 18:00:11 +04:00
|
|
|
|
|
|
|
// if src failed and there is no lowsrc
|
|
|
|
// or both failed to load, then notify the PresShell
|
|
|
|
if (imageFailedToLoad) {
|
|
|
|
if (presShell) {
|
2000-09-08 01:03:26 +04:00
|
|
|
// Also send error event
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_IMAGE_ERROR;
|
2000-09-20 01:47:04 +04:00
|
|
|
presShell->HandleEventWithTarget(&event,this,mContent,NS_EVENT_FLAG_INIT,&status);
|
2000-09-08 01:03:26 +04:00
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
nsAutoString usemap;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
|
|
|
|
// We failed to load the image. Notify the pres shell if we aren't an image map
|
|
|
|
if (usemap.Length() == 0) {
|
|
|
|
presShell->CantRenderReplacedElement(aPresContext, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
|
2000-01-12 11:28:24 +03:00
|
|
|
if (mParent) {
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mParent->ReflowDirtyChild(presShell, (nsIFrame*) this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(0, "No parent to pass the reflow request up to.");
|
1998-09-26 22:36:59 +04:00
|
|
|
}
|
|
|
|
}
|
2000-01-14 02:32:47 +03:00
|
|
|
|
2000-09-08 01:03:26 +04:00
|
|
|
if (mCanSendLoadEvent &&
|
|
|
|
!imageFailedToLoad &&
|
|
|
|
(NS_IMAGE_LOAD_STATUS_IMAGE_READY & aStatus) &&
|
|
|
|
presShell) {
|
|
|
|
// Send load event
|
|
|
|
mCanSendLoadEvent = PR_FALSE;
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_IMAGE_LOAD;
|
2000-09-20 01:47:04 +04:00
|
|
|
presShell->HandleEventWithTarget(&event,this,mContent,NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_CANT_BUBBLE,&status);
|
2000-09-08 01:03:26 +04:00
|
|
|
}
|
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
#if 0 // ifdef'ing out the deleting of the lowsrc image
|
|
|
|
// if the "src" image was change via script to an iage that
|
|
|
|
// didn't exist, the the author would expect the lowsrc to be displayed.
|
|
|
|
// now check to see if we have the entire low
|
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
nsIImage * image = mImageLoader.GetImage();
|
|
|
|
if (image) {
|
|
|
|
PRInt32 imgSrcLinesLoaded = image != nsnull?image->GetDecodedY2():-1;
|
|
|
|
if (image->GetDecodedY2() == image->GetHeight()) {
|
|
|
|
delete mLowSrcImageLoader;
|
|
|
|
mLowSrcImageLoader = nsnull;
|
|
|
|
}
|
|
|
|
NS_RELEASE(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-09-26 22:36:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
void
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-04-19 18:00:11 +04:00
|
|
|
PRBool cancelledReflow = PR_FALSE;
|
|
|
|
|
|
|
|
if (mLowSrcImageLoader != nsnull && !(mImageLoader.GetLoadStatus() & NS_IMAGE_LOAD_STATUS_IMAGE_READY)) {
|
|
|
|
PRBool gotDesiredSize = mLowSrcImageLoader->GetDesiredSize(aPresContext, &aReflowState, aDesiredSize);
|
|
|
|
/*if (gotDesiredSize) {
|
|
|
|
// We have our "final" desired size. Cancel any pending
|
|
|
|
// incremental reflows aimed at this frame.
|
|
|
|
nsIPresShell* shell;
|
|
|
|
aPresContext->GetShell(&shell);
|
|
|
|
if (shell) {
|
|
|
|
shell->CancelReflowCommand(this, nsnull);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must ask for desiredSize to start loading of image
|
|
|
|
// that seems like a bogus API
|
1999-04-24 00:00:14 +04:00
|
|
|
if (mImageLoader.GetDesiredSize(aPresContext, &aReflowState, aDesiredSize)) {
|
2000-04-19 18:00:11 +04:00
|
|
|
if (!cancelledReflow) {
|
|
|
|
// We have our "final" desired size. Cancel any pending
|
|
|
|
// incremental reflows aimed at this frame.
|
|
|
|
nsIPresShell* shell;
|
|
|
|
aPresContext->GetShell(&shell);
|
|
|
|
if (shell) {
|
|
|
|
shell->CancelReflowCommand(this, nsnull);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
1999-04-24 00:00:14 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
void
|
|
|
|
nsImageFrame::GetInnerArea(nsIPresContext* aPresContext,
|
|
|
|
nsRect& aInnerArea) const
|
|
|
|
{
|
|
|
|
aInnerArea.x = mBorderPadding.left;
|
|
|
|
aInnerArea.y = mBorderPadding.top;
|
|
|
|
aInnerArea.width = mRect.width -
|
|
|
|
(mBorderPadding.left + mBorderPadding.right);
|
|
|
|
aInnerArea.height = mRect.height -
|
|
|
|
(mBorderPadding.top + mBorderPadding.bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::Reflow(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageFrame", aReflowState.reason);
|
1998-11-20 20:21:02 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("enter nsImageFrame::Reflow: availSize=%d,%d",
|
1999-01-06 02:31:18 +03:00
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-11-20 20:21:02 +03:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
|
|
|
AddBordersAndPadding(aPresContext, aReflowState, aMetrics, mBorderPadding);
|
1998-11-20 20:21:02 +03:00
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
// If we have a percentage based width, then our MES width is 0
|
|
|
|
if (eStyleUnit_Percent == aReflowState.mStylePosition->mWidth.GetUnit()) {
|
2000-01-30 21:28:38 +03:00
|
|
|
aMetrics.maxElementSize->width = 0;
|
|
|
|
} else {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
}
|
1998-11-20 20:21:02 +03:00
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
2000-05-14 08:43:52 +04:00
|
|
|
if (aMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
aMetrics.mMaximumWidth = aMetrics.width;
|
|
|
|
}
|
1998-11-20 20:21:02 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("exit nsImageFrame::Reflow: size=%d,%d",
|
1998-11-20 20:21:02 +03:00
|
|
|
aMetrics.width, aMetrics.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Computes the width of the specified string. aMaxWidth specifies the maximum
|
|
|
|
// width available. Once this limit is reached no more characters are measured.
|
|
|
|
// The number of characters that fit within the maximum width are returned in
|
1998-10-02 05:12:39 +04:00
|
|
|
// aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected
|
|
|
|
// into the rendering context before this is called (for performance). MMP
|
1999-02-12 20:45:58 +03:00
|
|
|
void
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::MeasureString(const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nscoord aMaxWidth,
|
|
|
|
PRUint32& aMaxFit,
|
|
|
|
nsIRenderingContext& aContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nscoord totalWidth = 0;
|
|
|
|
nscoord spaceWidth;
|
1998-10-02 05:12:39 +04:00
|
|
|
aContext.GetWidth(' ', spaceWidth);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
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;
|
1998-10-02 05:12:39 +04:00
|
|
|
aContext.GetWidth(aString, len, width);
|
1998-09-09 02:34:40 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the alt-text to fit within the specified rectangle. Breaks lines
|
|
|
|
// between words if a word would extend past the edge of the rectangle
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::DisplayAltText(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsString& aAltText,
|
|
|
|
const nsRect& aRect)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
const nsStyleColor* color =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleFont* font =
|
|
|
|
(const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
|
|
|
|
// Set font and color
|
|
|
|
aRenderingContext.SetColor(color->mColor);
|
|
|
|
aRenderingContext.SetFont(font->mFont);
|
|
|
|
|
|
|
|
// Format the text to display within the formatting rect
|
1998-10-30 05:08:25 +03:00
|
|
|
nsIFontMetrics* fm;
|
|
|
|
aRenderingContext.GetFontMetrics(fm);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
nscoord maxDescent, height;
|
|
|
|
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.GetUnicode();
|
|
|
|
PRInt32 strLen = aAltText.Length();
|
|
|
|
nscoord y = aRect.y;
|
|
|
|
while ((strLen > 0) && ((y + maxDescent) < aRect.YMost())) {
|
|
|
|
// Determine how much of the text to display on this line
|
|
|
|
PRUint32 maxFit; // number of characters that fit
|
1999-02-12 20:45:58 +03:00
|
|
|
MeasureString(str, strLen, aRect.width, maxFit, aRenderingContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Display the text
|
1999-01-28 08:03:58 +03:00
|
|
|
aRenderingContext.DrawString(str, maxFit, aRect.x, y);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Move to the next line
|
|
|
|
str += maxFit;
|
|
|
|
strLen -= maxFit;
|
|
|
|
y += height;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(fm);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nsRecessedBorder : public nsStyleSpacing {
|
|
|
|
nsRecessedBorder(nscoord aBorderWidth)
|
|
|
|
: nsStyleSpacing()
|
|
|
|
{
|
|
|
|
nsStyleCoord styleCoord(aBorderWidth);
|
|
|
|
|
|
|
|
mBorder.SetLeft(styleCoord);
|
|
|
|
mBorder.SetTop(styleCoord);
|
|
|
|
mBorder.SetRight(styleCoord);
|
|
|
|
mBorder.SetBottom(styleCoord);
|
1998-12-07 21:53:07 +03:00
|
|
|
|
|
|
|
mBorderStyle[0] = NS_STYLE_BORDER_STYLE_INSET;
|
|
|
|
mBorderStyle[1] = NS_STYLE_BORDER_STYLE_INSET;
|
|
|
|
mBorderStyle[2] = NS_STYLE_BORDER_STYLE_INSET;
|
|
|
|
mBorderStyle[3] = NS_STYLE_BORDER_STYLE_INSET;
|
|
|
|
|
|
|
|
mBorderColor[0] = 0;
|
|
|
|
mBorderColor[1] = 0;
|
|
|
|
mBorderColor[2] = 0;
|
|
|
|
mBorderColor[3] = 0;
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
mHasCachedMargin = mHasCachedPadding = mHasCachedBorder = PR_FALSE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-09-22 07:34:44 +04:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::DisplayAltFeedback(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
PRInt32 aIconId)
|
1998-09-22 07:34:44 +04:00
|
|
|
{
|
1999-09-17 01:37:37 +04:00
|
|
|
// Calculate the inner area
|
1998-09-22 07:34:44 +04:00
|
|
|
nsRect inner;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetInnerArea(aPresContext, inner);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Display a recessed one pixel border
|
|
|
|
float p2t;
|
|
|
|
nscoord borderEdgeWidth;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-09-17 01:37:37 +04:00
|
|
|
borderEdgeWidth = NSIntPixelsToTwips(1, 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);
|
1998-09-22 07:34:44 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, inner,
|
1999-01-23 01:26:29 +03:00
|
|
|
inner, recessedBorder, mStyleContext, 0);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// Adjust the inner rect to account for the one pixel recessed border,
|
|
|
|
// and a six pixel padding on each edge
|
|
|
|
inner.Deflate(NSIntPixelsToTwips(7, p2t), NSIntPixelsToTwips(7, p2t));
|
|
|
|
if (inner.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip so we don't render outside the inner rect
|
1999-09-17 01:37:37 +04:00
|
|
|
PRBool clipState;
|
1998-09-22 07:34:44 +04:00
|
|
|
aRenderingContext.PushState();
|
1998-10-30 05:08:25 +03:00
|
|
|
aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect, clipState);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// Display the icon
|
1998-10-30 05:08:25 +03:00
|
|
|
nsIDeviceContext* dc;
|
|
|
|
aRenderingContext.GetDeviceContext(dc);
|
1998-09-22 07:34:44 +04:00
|
|
|
nsIImage* icon;
|
|
|
|
|
1999-07-31 09:59:12 +04:00
|
|
|
if (NS_SUCCEEDED(dc->LoadIconImage(aIconId, icon)) && icon) {
|
1998-09-22 07:34:44 +04:00
|
|
|
aRenderingContext.DrawImage(icon, inner.x, inner.y);
|
|
|
|
|
|
|
|
// Reduce the inner rect by the width of the icon, and leave an
|
|
|
|
// additional six pixels padding
|
|
|
|
PRInt32 iconWidth = NSIntPixelsToTwips(icon->GetWidth() + 6, p2t);
|
|
|
|
inner.x += iconWidth;
|
|
|
|
inner.width -= iconWidth;
|
|
|
|
|
|
|
|
NS_RELEASE(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(dc);
|
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
|
|
|
nsAutoString altText;
|
1998-12-20 04:21:23 +03:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::alt, altText)) {
|
1998-09-22 07:34:44 +04:00
|
|
|
DisplayAltText(aPresContext, aRenderingContext, altText, inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-30 05:08:25 +03:00
|
|
|
aRenderingContext.PopState(clipState);
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_METHOD
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::Paint(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
2000-03-17 13:15:13 +03:00
|
|
|
if (disp->IsVisible() && mRect.width && mRect.height) {
|
1998-09-09 02:34:40 +04:00
|
|
|
// First paint background and borders
|
1998-12-18 18:54:23 +03:00
|
|
|
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
|
|
|
|
aWhichLayer);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
// first get to see if lowsrc image is here
|
|
|
|
PRInt32 lowSrcLinesLoaded = -1;
|
|
|
|
PRInt32 imgSrcLinesLoaded = -1;
|
|
|
|
nsIImage * lowImage = nsnull;
|
|
|
|
nsIImage * image = nsnull;
|
|
|
|
|
|
|
|
// if lowsrc is here
|
|
|
|
if (mLowSrcImageLoader != nsnull) {
|
|
|
|
lowImage = mLowSrcImageLoader->GetImage();
|
|
|
|
lowSrcLinesLoaded = lowImage != nsnull?lowImage->GetDecodedY2():-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = mImageLoader.GetImage();
|
|
|
|
imgSrcLinesLoaded = image != nsnull?image->GetDecodedY2():-1;
|
|
|
|
|
|
|
|
if (nsnull == image && nsnull == lowImage) {
|
1998-09-22 08:01:16 +04:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
|
|
|
// indicating the status
|
2000-04-01 04:13:51 +04:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer &&
|
|
|
|
!mInitialLoadCompleted) {
|
1998-12-18 18:54:23 +03:00
|
|
|
DisplayAltFeedback(aPresContext, aRenderingContext,
|
|
|
|
mImageLoader.GetLoadImageFailed()
|
|
|
|
? NS_ICON_BROKEN_IMAGE
|
|
|
|
: NS_ICON_LOADING_IMAGE);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
else {
|
2000-04-01 04:13:51 +04:00
|
|
|
mInitialLoadCompleted = PR_TRUE;
|
1999-04-14 01:51:20 +04:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
1999-04-10 21:32:33 +04:00
|
|
|
// Now render the image into our content area (the area inside the
|
|
|
|
// borders and padding)
|
1998-12-18 18:54:23 +03:00
|
|
|
nsRect inner;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetInnerArea(aPresContext, inner);
|
1999-04-10 21:32:33 +04:00
|
|
|
if (mImageLoader.GetLoadImageFailed()) {
|
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
2000-07-20 18:50:17 +04:00
|
|
|
if (image != nsnull) {
|
|
|
|
inner.width = NSIntPixelsToTwips(image->GetWidth(), p2t);
|
|
|
|
inner.height = NSIntPixelsToTwips(image->GetHeight(), p2t);
|
|
|
|
} else if (lowImage != nsnull) {
|
|
|
|
inner.width = NSIntPixelsToTwips(lowImage->GetWidth(), p2t);
|
|
|
|
inner.height = NSIntPixelsToTwips(lowImage->GetHeight(), p2t);
|
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
2000-04-19 18:00:11 +04:00
|
|
|
|
|
|
|
if (image != nsnull && imgSrcLinesLoaded > 0) {
|
|
|
|
aRenderingContext.DrawImage(image, inner);
|
2000-08-15 02:01:05 +04:00
|
|
|
} else if (lowImage != nsnull && lowSrcLinesLoaded > 0) {
|
|
|
|
aRenderingContext.DrawImage(lowImage, inner);
|
2000-04-19 18:00:11 +04:00
|
|
|
}
|
2000-08-15 02:01:05 +04:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageMap* map = GetImageMap(aPresContext);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
if (nsnull != map) {
|
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(aPresContext, inner);
|
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(inner.x, inner.y);
|
|
|
|
map->Draw(aPresContext, aRenderingContext);
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1999-04-10 21:32:33 +04:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
|
|
|
|
GetShowFrameBorders()) {
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageMap* map = GetImageMap(aPresContext);
|
1999-04-10 21:32:33 +04:00
|
|
|
if (nsnull != map) {
|
|
|
|
nsRect inner;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetInnerArea(aPresContext, inner);
|
1999-04-10 21:32:33 +04:00
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(inner.x, inner.y);
|
|
|
|
map->Draw(aPresContext, aRenderingContext);
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
}
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
NS_IF_RELEASE(lowImage);
|
1999-12-03 03:06:32 +03:00
|
|
|
NS_IF_RELEASE(image);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-05-17 04:21:18 +04:00
|
|
|
|
|
|
|
return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:19 +03:00
|
|
|
nsImageMap*
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageFrame::GetImageMap(nsIPresContext* aPresContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
if (nsnull == mImageMap) {
|
|
|
|
nsAutoString usemap;
|
1998-12-20 04:21:23 +03:00
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (0 == usemap.Length()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-08-20 02:22:02 +04:00
|
|
|
// Strip out whitespace in the name for navigator compatability
|
|
|
|
// XXX NAV QUIRK
|
|
|
|
usemap.StripWhitespace();
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
mContent->GetDocument(doc);
|
|
|
|
if (nsnull == doc) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usemap.First() == '#') {
|
|
|
|
usemap.Cut(0, 1);
|
|
|
|
}
|
|
|
|
nsIHTMLDocument* hdoc;
|
|
|
|
nsresult rv = doc->QueryInterface(kIHTMLDocumentIID, (void**)&hdoc);
|
|
|
|
NS_RELEASE(doc);
|
1999-01-09 03:13:19 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIDOMHTMLMapElement* map;
|
1998-09-09 02:34:40 +04:00
|
|
|
rv = hdoc->GetImageMap(usemap, &map);
|
|
|
|
NS_RELEASE(hdoc);
|
1999-01-09 03:13:19 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-08-18 10:27:42 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
1999-01-09 03:13:19 +03:00
|
|
|
mImageMap = new nsImageMap();
|
|
|
|
if (nsnull != mImageMap) {
|
1999-10-08 05:49:06 +04:00
|
|
|
NS_ADDREF(mImageMap);
|
2000-08-18 10:27:42 +04:00
|
|
|
mImageMap->Init(presShell, this, map);
|
1999-01-09 03:13:19 +03:00
|
|
|
}
|
1999-01-30 04:04:35 +03:00
|
|
|
NS_IF_RELEASE(map);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-09 03:13:19 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
return mImageMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::TriggerLink(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
const nsString& aURLSpec,
|
|
|
|
const nsString& aTargetSpec,
|
|
|
|
PRBool aClick)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-08-09 00:35:12 +04:00
|
|
|
// We get here with server side image map
|
1998-09-09 02:34:40 +04:00
|
|
|
nsILinkHandler* handler = nsnull;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetLinkHandler(&handler);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (nsnull != handler) {
|
|
|
|
if (aClick) {
|
2000-08-09 00:35:12 +04:00
|
|
|
nsresult proceed = NS_OK;
|
|
|
|
// Check that this page is allowed to load this URI.
|
|
|
|
// Almost a copy of the similarly named method in nsGenericElement
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
|
2000-09-14 03:57:52 +04:00
|
|
|
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
2000-08-09 00:35:12 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> ps;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = aPresContext->GetShell(getter_AddRefs(ps));
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (NS_SUCCEEDED(rv) && ps)
|
|
|
|
rv = ps->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
if (NS_SUCCEEDED(rv) && doc)
|
|
|
|
baseURI = dont_AddRef(doc->GetDocumentURL());
|
|
|
|
nsCOMPtr<nsIURI> absURI;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_NewURI(getter_AddRefs(absURI), aURLSpec, baseURI);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2000-10-14 02:59:47 +04:00
|
|
|
proceed = securityManager->CheckLoadURI(baseURI, absURI, nsIScriptSecurityManager::STANDARD);
|
2000-08-09 00:35:12 +04:00
|
|
|
|
|
|
|
// Only pass off the click event if the script security manager
|
|
|
|
// says it's ok.
|
|
|
|
if (NS_SUCCEEDED(proceed))
|
|
|
|
handler->OnLinkClick(mContent, eLinkVerb_Replace, aURLSpec.GetUnicode(), aTargetSpec.GetUnicode());
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-04-22 03:35:12 +04:00
|
|
|
handler->OnOverLink(mContent, aURLSpec.GetUnicode(), aTargetSpec.GetUnicode());
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-01-30 03:34:06 +03:00
|
|
|
NS_RELEASE(handler);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::IsServerImageMap()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nsAutoString ismap;
|
1999-07-08 23:38:08 +04:00
|
|
|
return NS_CONTENT_ATTR_HAS_VALUE ==
|
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::ismap, ismap);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::GetSuppress()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nsAutoString s;
|
1999-07-08 23:38:08 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::suppress, s)) {
|
1998-09-09 02:34:40 +04:00
|
|
|
if (s.EqualsIgnoreCase("true")) {
|
|
|
|
return SUPPRESS;
|
|
|
|
} else if (s.EqualsIgnoreCase("false")) {
|
|
|
|
return DONT_SUPPRESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DEFAULT_SUPPRESS;
|
|
|
|
}
|
|
|
|
|
1999-07-08 23:38:08 +04:00
|
|
|
//XXX the event come's in in view relative coords, but really should
|
|
|
|
//be in frame relative coords by the time it hits our frame.
|
|
|
|
|
|
|
|
// Translate an point that is relative to our view (or a containing
|
|
|
|
// view) into a localized pixel coordinate that is relative to the
|
|
|
|
// content area of this frame (inside the border+padding).
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::TranslateEventCoords(nsIPresContext* aPresContext,
|
1999-07-08 23:38:08 +04:00
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsPoint& aResult)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
nsIView* view;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetView(aPresContext, &view);
|
1999-07-08 23:38:08 +04:00
|
|
|
if (nsnull == view) {
|
|
|
|
nsPoint offset;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, offset, &view);
|
1999-07-08 23:38:08 +04:00
|
|
|
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;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetInnerArea(aPresContext, inner);
|
1999-07-08 23:38:08 +04:00
|
|
|
x -= inner.x;
|
|
|
|
y -= inner.y;
|
|
|
|
|
|
|
|
// Translate the coordinates from twips to pixels
|
|
|
|
float t2p;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
1999-07-08 23:38:08 +04:00
|
|
|
aResult.x = NSTwipsToIntPixels(x, t2p);
|
|
|
|
aResult.y = NSTwipsToIntPixels(y, t2p);
|
|
|
|
}
|
|
|
|
|
1999-07-08 23:44:42 +04:00
|
|
|
PRBool
|
1999-07-08 23:38:08 +04:00
|
|
|
nsImageFrame::GetAnchorHREF(nsString& aResult)
|
|
|
|
{
|
1999-07-08 23:44:42 +04:00
|
|
|
PRBool status = PR_FALSE;
|
1999-07-08 23:38:08 +04:00
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
// Walk up the content tree, looking for an nsIDOMAnchorElement
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mContent->GetParent(*getter_AddRefs(content));
|
|
|
|
while (content) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(content));
|
|
|
|
if (anchor) {
|
|
|
|
anchor->GetHref(aResult);
|
1999-07-08 23:44:42 +04:00
|
|
|
if (aResult.Length() > 0) {
|
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
1999-07-08 23:38:08 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
content->GetParent(*getter_AddRefs(parent));
|
|
|
|
content = parent;
|
|
|
|
}
|
1999-07-08 23:44:42 +04:00
|
|
|
return status;
|
1999-07-08 23:38:08 +04:00
|
|
|
}
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetContentForEvent(nsIPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIContent** aContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
|
|
|
nsImageMap* map;
|
2000-08-18 10:27:42 +04:00
|
|
|
map = GetImageMap(aPresContext);
|
2000-02-11 04:24:59 +03:00
|
|
|
|
|
|
|
if (nsnull != map) {
|
|
|
|
nsPoint p;
|
|
|
|
TranslateEventCoords(aPresContext, aEvent->point, p);
|
|
|
|
nsAutoString absURL, target, altText;
|
|
|
|
PRBool suppress;
|
|
|
|
PRBool inside = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIContent> area;
|
|
|
|
inside = map->IsInside(p.x, p.y, getter_AddRefs(area),
|
|
|
|
absURL, target, altText,
|
|
|
|
&suppress);
|
|
|
|
if (inside && area) {
|
|
|
|
*aContent = area;
|
|
|
|
NS_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContent(aContent);
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// XXX what should clicks on transparent pixels do?
|
|
|
|
NS_METHOD
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::HandleEvent(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
1999-01-09 03:13:19 +03:00
|
|
|
nsImageMap* map;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MOVE:
|
1999-08-20 02:22:02 +04:00
|
|
|
{
|
2000-08-18 10:27:42 +04:00
|
|
|
map = GetImageMap(aPresContext);
|
1999-08-20 02:22:02 +04:00
|
|
|
PRBool isServerMap = IsServerImageMap();
|
|
|
|
if ((nsnull != map) || isServerMap) {
|
|
|
|
nsPoint p;
|
|
|
|
TranslateEventCoords(aPresContext, aEvent->point, p);
|
|
|
|
nsAutoString absURL, target, altText;
|
|
|
|
PRBool suppress;
|
1999-02-06 05:07:49 +03:00
|
|
|
PRBool inside = PR_FALSE;
|
2000-02-11 04:24:59 +03:00
|
|
|
// 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!)
|
1999-08-20 02:22:02 +04:00
|
|
|
if (nsnull != map) {
|
2000-02-11 04:24:59 +03:00
|
|
|
nsCOMPtr<nsIContent> area;
|
|
|
|
inside = map->IsInside(p.x, p.y, getter_AddRefs(area),
|
|
|
|
absURL, target, altText,
|
|
|
|
&suppress);
|
1999-01-15 04:57:58 +03:00
|
|
|
}
|
1999-08-20 02:22:02 +04:00
|
|
|
|
|
|
|
if (!inside && isServerMap) {
|
|
|
|
suppress = GetSuppress();
|
|
|
|
nsIURI* baseURL = nsnull;
|
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
if (NS_SUCCEEDED(mContent->QueryInterface(kIHTMLContentIID,
|
|
|
|
(void**)&htmlContent))) {
|
|
|
|
htmlContent->GetBaseURL(baseURL);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIDocument* doc;
|
|
|
|
if (NS_SUCCEEDED(mContent->GetDocument(doc))) {
|
|
|
|
doc->GetBaseURL(baseURL);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Server side image maps use the href in a containing anchor
|
|
|
|
// element to provide the basis for the destination url.
|
|
|
|
nsAutoString src;
|
|
|
|
if (GetAnchorHREF(src)) {
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_MakeAbsoluteURI(absURL, src, baseURL);
|
1999-08-20 02:22:02 +04:00
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
char cbuf[50];
|
|
|
|
PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", p.x, p.y);
|
2000-04-03 15:39:09 +04:00
|
|
|
absURL.AppendWithConversion(cbuf);
|
1999-08-20 02:22:02 +04:00
|
|
|
PRBool clicked = PR_FALSE;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
1999-11-24 09:03:41 +03:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
1999-08-20 02:22:02 +04:00
|
|
|
clicked = PR_TRUE;
|
|
|
|
}
|
|
|
|
TriggerLink(aPresContext, absURL, target, clicked);
|
1999-07-08 23:44:42 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-04-13 01:24:07 +04:00
|
|
|
default:
|
|
|
|
break;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-04-13 01:24:07 +04:00
|
|
|
|
|
|
|
return nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-07-08 23:38:08 +04:00
|
|
|
//XXX This will need to be rewritten once we have content for areas
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_METHOD
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageFrame::GetCursor(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsPoint& aPoint,
|
|
|
|
PRInt32& aCursor)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageMap* map = GetImageMap(aPresContext);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (nsnull != map) {
|
1999-07-08 23:38:08 +04:00
|
|
|
nsPoint p;
|
|
|
|
TranslateEventCoords(aPresContext, aPoint, p);
|
1998-11-18 08:25:26 +03:00
|
|
|
aCursor = NS_STYLE_CURSOR_DEFAULT;
|
1999-07-08 23:38:08 +04:00
|
|
|
if (map->IsInside(p.x, p.y)) {
|
1998-11-24 01:21:13 +03:00
|
|
|
// Use style defined cursor if one is provided, otherwise when
|
|
|
|
// the cursor style is "auto" we use the pointer cursor.
|
|
|
|
const nsStyleColor* styleColor;
|
|
|
|
GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)styleColor);
|
|
|
|
aCursor = styleColor->mCursor;
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor) {
|
|
|
|
aCursor = NS_STYLE_CURSOR_POINTER;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
return nsFrame::GetCursor(aPresContext, aPoint, aCursor);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-16 03:16:45 +04:00
|
|
|
PRInt32 aNameSpaceID,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-09-30 03:48:07 +04:00
|
|
|
nsresult rv = nsLeafFrame::AttributeChanged(aPresContext, aChild,
|
1999-10-16 03:16:45 +04:00
|
|
|
aNameSpaceID, aAttribute, aHint);
|
1998-09-29 01:22:31 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-30 03:48:07 +04:00
|
|
|
if (nsHTMLAtoms::src == aAttribute) {
|
1999-04-14 01:51:20 +04:00
|
|
|
nsAutoString oldSRC, newSRC;
|
1999-01-15 04:57:58 +03:00
|
|
|
mImageLoader.GetURLSpec(oldSRC);
|
1999-10-16 03:16:45 +04:00
|
|
|
aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::src, newSRC);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (!oldSRC.Equals(newSRC)) {
|
1999-04-14 01:51:20 +04:00
|
|
|
#ifdef NOISY_IMAGE_LOADING
|
|
|
|
ListTag(stdout);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": new image source; old='");
|
|
|
|
fputs(oldSRC, stdout);
|
|
|
|
printf("' new='");
|
|
|
|
fputs(newSRC, stdout);
|
|
|
|
printf("'\n");
|
1998-09-09 02:34:40 +04:00
|
|
|
#endif
|
2000-07-01 06:26:30 +04:00
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
if (mImageLoader.IsImageSizeKnown()) {
|
|
|
|
mImageLoader.UpdateURLSpec(aPresContext, newSRC);
|
|
|
|
PRUint32 loadStatus = mImageLoader.GetLoadStatus();
|
|
|
|
if (loadStatus & NS_IMAGE_LOAD_STATUS_IMAGE_READY) {
|
|
|
|
// Trigger a paint now because image-loader won't if the
|
|
|
|
// image is already loaded and ready to go.
|
1999-10-26 08:44:41 +04:00
|
|
|
Invalidate(aPresContext, nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);
|
1999-04-14 01:51:20 +04:00
|
|
|
}
|
|
|
|
}
|
2000-07-01 06:26:30 +04:00
|
|
|
else {
|
|
|
|
// Stop the earlier image load
|
|
|
|
mImageLoader.StopLoadImage(aPresContext);
|
|
|
|
|
2000-09-08 01:03:26 +04:00
|
|
|
mCanSendLoadEvent = PR_TRUE;
|
|
|
|
|
2000-07-01 06:26:30 +04:00
|
|
|
// Update the URL and start the new image load
|
|
|
|
mImageLoader.UpdateURLSpec(aPresContext, newSRC);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else if (nsHTMLAtoms::width == aAttribute || nsHTMLAtoms::height == aAttribute)
|
|
|
|
{ // XXX: could check for new width == old width, and make that a no-op
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mParent->ReflowDirtyChild(presShell, (nsIFrame*) this);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-25 20:35:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::imageFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-04 06:06:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|
|
|
{
|
2000-04-15 19:49:57 +04:00
|
|
|
mImageLoader.GetIntrinsicSize(aSize);
|
2000-01-04 06:06:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-09 02:52:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetNaturalImageSize(PRUint32* naturalWidth,
|
|
|
|
PRUint32 *naturalHeight)
|
|
|
|
{
|
|
|
|
mImageLoader.GetNaturalImageSize(naturalWidth, naturalHeight);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-07 02:41:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IsImageComplete(PRBool* aComplete)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aComplete);
|
2000-08-17 10:28:47 +04:00
|
|
|
*aComplete = ((mImageLoader.GetLoadStatus() & NS_IMAGE_LOAD_STATUS_IMAGE_READY) != 0);
|
2000-01-07 02:41:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1999-08-31 07:09:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
PRUint32 sum;
|
|
|
|
mImageLoader.SizeOf(aHandler, &sum);
|
|
|
|
sum += sizeof(*this) - sizeof(mImageLoader);
|
|
|
|
if (mImageMap) {
|
|
|
|
PRBool recorded;
|
|
|
|
aHandler->RecordObject((void*) mImageMap, &recorded);
|
|
|
|
if (!recorded) {
|
|
|
|
PRUint32 mapSize;
|
|
|
|
mImageMap->SizeOf(aHandler, &mapSize);
|
|
|
|
aHandler->AddSize(nsLayoutAtoms::imageMap, mapSize);
|
|
|
|
}
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
*aResult = sum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|