1998-09-08 22:34:40 +00:00
|
|
|
/* -*- 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 "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLImage.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLeafFrame.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"
|
|
|
|
#include "nsIImageMap.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
1998-09-23 02:30:21 +00:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsISizeOfHandler.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
1998-09-20 00:08:24 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
|
1998-11-13 21:31:50 +00:00
|
|
|
#ifndef _WIN32
|
1998-09-08 22:34:40 +00:00
|
|
|
#define BROKEN_IMAGE_URL "resource:/res/html/broken-image.gif"
|
1998-11-13 21:31:50 +00:00
|
|
|
#endif
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
#define XP_IS_SPACE(_ch) \
|
|
|
|
(((_ch) == ' ') || ((_ch) == '\t') || ((_ch) == '\n'))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsHTMLImageLoader::nsHTMLImageLoader()
|
|
|
|
{
|
|
|
|
mImageLoader = nsnull;
|
|
|
|
mLoadImageFailed = PR_FALSE;
|
1998-11-13 21:31:50 +00:00
|
|
|
#ifndef _WIN32
|
1998-09-08 22:34:40 +00:00
|
|
|
mLoadBrokenImageFailed = PR_FALSE;
|
1998-11-13 21:31:50 +00:00
|
|
|
#endif
|
1998-09-08 22:34:40 +00:00
|
|
|
mURLSpec = nsnull;
|
|
|
|
mBaseHREF = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLImageLoader::~nsHTMLImageLoader()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mImageLoader);
|
|
|
|
if (nsnull != mURLSpec) {
|
|
|
|
delete mURLSpec;
|
|
|
|
}
|
|
|
|
if (nsnull != mBaseHREF) {
|
|
|
|
delete mBaseHREF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLImageLoader::SizeOf(nsISizeOfHandler* aHandler) const
|
|
|
|
{
|
|
|
|
aHandler->Add(sizeof(*this));
|
|
|
|
if (!aHandler->HaveSeen(mURLSpec)) {
|
|
|
|
mURLSpec->SizeOf(aHandler);
|
|
|
|
}
|
|
|
|
if (!aHandler->HaveSeen(mImageLoader)) {
|
|
|
|
mImageLoader->SizeOf(aHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIImage*
|
|
|
|
nsHTMLImageLoader::GetImage()
|
|
|
|
{
|
|
|
|
nsIImage* image = nsnull;
|
|
|
|
if (nsnull != mImageLoader) {
|
|
|
|
mImageLoader->GetImage(image);
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLImageLoader::SetURL(const nsString& aURLSpec)
|
|
|
|
{
|
|
|
|
if (nsnull != mURLSpec) {
|
|
|
|
delete mURLSpec;
|
|
|
|
}
|
|
|
|
mURLSpec = new nsString(aURLSpec);
|
|
|
|
if (nsnull == mURLSpec) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLImageLoader::SetBaseHREF(const nsString& aBaseHREF)
|
|
|
|
{
|
|
|
|
if (nsnull != mBaseHREF) {
|
|
|
|
delete mBaseHREF;
|
|
|
|
}
|
|
|
|
mBaseHREF = new nsString(aBaseHREF);
|
|
|
|
if (nsnull == mBaseHREF) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
1998-09-26 18:36:59 +00:00
|
|
|
nsFrameImageLoaderCB aCallBack,
|
1998-09-08 22:34:40 +00:00
|
|
|
PRBool aNeedSizeUpdate,
|
|
|
|
PRIntn& aLoadStatus)
|
|
|
|
{
|
|
|
|
aLoadStatus = NS_IMAGE_LOAD_STATUS_NONE;
|
|
|
|
|
|
|
|
// Get absolute url the first time through
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString src;
|
|
|
|
if (mLoadImageFailed || (nsnull == mURLSpec)) {
|
1998-11-13 17:00:54 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
mLoadImageFailed = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
1998-09-08 22:34:40 +00:00
|
|
|
src.Append(BROKEN_IMAGE_URL);
|
1998-11-13 17:00:54 +00:00
|
|
|
#endif
|
1998-11-21 04:04:41 +00:00
|
|
|
} else if (nsnull == mImageLoader) {
|
1998-09-08 22:34:40 +00:00
|
|
|
nsAutoString baseURL;
|
|
|
|
if (nsnull != mBaseHREF) {
|
|
|
|
baseURL = *mBaseHREF;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get documentURL
|
|
|
|
nsIPresShell* shell;
|
|
|
|
shell = aPresContext->GetShell();
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
nsIURL* docURL = doc->GetDocumentURL();
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
nsresult rv = NS_MakeAbsoluteURL(docURL, baseURL, *mURLSpec, src);
|
|
|
|
|
|
|
|
// Release references
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
NS_RELEASE(docURL);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
1998-09-26 18:36:59 +00:00
|
|
|
rv = aPresContext->StartLoadImage(src, nsnull, aForFrame, aCallBack,
|
|
|
|
aNeedSizeUpdate, mImageLoader);
|
1998-09-08 22:34:40 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Examine current image load status
|
|
|
|
mImageLoader->GetImageLoadStatus(aLoadStatus);
|
|
|
|
if (0 != (aLoadStatus & NS_IMAGE_LOAD_STATUS_ERROR)) {
|
|
|
|
NS_RELEASE(mImageLoader);
|
1998-11-13 21:31:50 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Display broken icon along with alt-text
|
|
|
|
mLoadImageFailed = PR_TRUE;
|
|
|
|
#else
|
1998-09-08 22:34:40 +00:00
|
|
|
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;
|
1998-09-26 22:48:52 +00:00
|
|
|
return StartLoadImage(aPresContext, aForFrame, nsnull,
|
|
|
|
aNeedSizeUpdate, aLoadStatus);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
1998-11-13 21:31:50 +00:00
|
|
|
#endif
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
|
1998-10-02 04:10:00 +00:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1998-09-26 18:36:59 +00:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsFrameImageLoaderCB aCallBack,
|
1998-10-01 04:46:11 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1998-10-12 17:00:32 +00:00
|
|
|
// Start the image loading
|
1998-09-08 22:34:40 +00:00
|
|
|
PRIntn loadStatus;
|
1998-10-12 17:00:32 +00:00
|
|
|
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
|
1998-11-01 01:29:00 +00:00
|
|
|
!(aReflowState.HaveFixedContentWidth() && aReflowState.HaveFixedContentHeight()),
|
1998-10-12 17:00:32 +00:00
|
|
|
loadStatus);
|
|
|
|
|
|
|
|
// Choose reflow size
|
1998-11-01 01:29:00 +00:00
|
|
|
if (aReflowState.HaveFixedContentWidth() ||
|
|
|
|
aReflowState.HaveFixedContentHeight()) {
|
|
|
|
if (aReflowState.HaveFixedContentWidth() &&
|
|
|
|
aReflowState.HaveFixedContentHeight()) {
|
1998-10-12 17:00:32 +00:00
|
|
|
// The image is fully constrained. Use the constraints directly.
|
|
|
|
aDesiredSize.width = aReflowState.minWidth;
|
|
|
|
aDesiredSize.height = aReflowState.minHeight;
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-10-12 17:00:32 +00:00
|
|
|
// The image is partially constrained. Preserve aspect ratio of
|
|
|
|
// image with unbound dimension.
|
1998-09-08 22:34:40 +00:00
|
|
|
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
|
|
|
|
(nsnull == mImageLoader)) {
|
|
|
|
// Provide a dummy size for now; later on when the image size
|
|
|
|
// shows up we will reflow to the new size.
|
|
|
|
aDesiredSize.width = 1;
|
|
|
|
aDesiredSize.height = 1;
|
|
|
|
}
|
|
|
|
else {
|
1998-11-14 01:52:27 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(p2t);
|
1998-09-08 22:34:40 +00:00
|
|
|
nsSize imageSize;
|
|
|
|
mImageLoader->GetSize(imageSize);
|
|
|
|
float imageWidth = imageSize.width * p2t;
|
|
|
|
float imageHeight = imageSize.height * p2t;
|
|
|
|
if (0.0f != imageHeight) {
|
1998-11-01 01:29:00 +00:00
|
|
|
if (aReflowState.HaveFixedContentWidth()) {
|
1998-09-08 22:34:40 +00:00
|
|
|
// We have a width, and an auto height. Compute height
|
|
|
|
// from width.
|
1998-10-12 17:00:32 +00:00
|
|
|
aDesiredSize.width = aReflowState.minWidth;
|
|
|
|
aDesiredSize.height = (nscoord)
|
|
|
|
NSToIntRound(aReflowState.minWidth * imageHeight / imageWidth);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We have a height and an auto width. Compute width from
|
|
|
|
// height.
|
1998-10-12 17:00:32 +00:00
|
|
|
aDesiredSize.height = aReflowState.minHeight;
|
|
|
|
aDesiredSize.width = (nscoord)
|
|
|
|
NSToIntRound(aReflowState.minHeight * imageWidth / imageHeight);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Screwy image
|
|
|
|
aDesiredSize.width = 1;
|
|
|
|
aDesiredSize.height = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1998-10-12 17:00:32 +00:00
|
|
|
// The image is unconstrained
|
1998-09-08 22:34:40 +00:00
|
|
|
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
|
|
|
|
(nsnull == mImageLoader)) {
|
|
|
|
// Provide a dummy size for now; later on when the image size
|
|
|
|
// shows up we will reflow to the new size.
|
|
|
|
aDesiredSize.width = 1;
|
|
|
|
aDesiredSize.height = 1;
|
|
|
|
} else {
|
1998-11-14 01:52:27 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(p2t);
|
1998-09-08 22:34:40 +00:00
|
|
|
nsSize imageSize;
|
|
|
|
mImageLoader->GetSize(imageSize);
|
|
|
|
aDesiredSize.width = NSIntPixelsToTwips(imageSize.width, p2t);
|
|
|
|
aDesiredSize.height = NSIntPixelsToTwips(imageSize.height, p2t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-13 21:31:50 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLImageLoader::GetLoadImageFailed() const
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if (nsnull != mImageLoader) {
|
|
|
|
PRIntn loadStatus;
|
|
|
|
|
|
|
|
// Ask the image loader whether the load failed
|
|
|
|
mImageLoader->GetImageLoadStatus(loadStatus);
|
|
|
|
result = (loadStatus & NS_IMAGE_LOAD_STATUS_ERROR) == NS_IMAGE_LOAD_STATUS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
result |= PRBool(mLoadImageFailed);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewImageFrame(nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aResult)
|
|
|
|
{
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame* frame = new nsImageFrame(aContent, aParentFrame);
|
1998-09-08 22:34:40 +00:00
|
|
|
if (nsnull == frame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aResult = frame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::nsImageFrame(nsIContent* aContent, nsIFrame* aParentFrame)
|
1998-09-08 22:34:40 +00:00
|
|
|
: nsLeafFrame(aContent, aParentFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::DeleteFrame(nsIPresContext& aPresContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mImageMap);
|
|
|
|
|
|
|
|
// Release image loader first so that it's refcnt can go to zero
|
|
|
|
mImageLoader.DestroyLoader();
|
|
|
|
|
|
|
|
return nsLeafFrame::DeleteFrame(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::SizeOf(nsISizeOfHandler* aHandler) const
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
aHandler->Add(sizeof(*this));
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::SizeOfWithoutThis(aHandler);
|
1998-09-08 22:34:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
ImageFrameSuper::SizeOfWithoutThis(aHandler);
|
|
|
|
mImageLoader.SizeOf(aHandler);
|
|
|
|
if (!aHandler->HaveSeen(mImageMap)) {
|
|
|
|
mImageMap->SizeOf(aHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-26 18:36:59 +00:00
|
|
|
static nsresult
|
|
|
|
UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame,
|
|
|
|
PRIntn aStatus)
|
|
|
|
{
|
|
|
|
if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
|
|
|
|
// Now that the size is available, trigger a content-changed reflow
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
aFrame->GetContent(content);
|
|
|
|
if (nsnull != content) {
|
|
|
|
nsIDocument* document = nsnull;
|
|
|
|
content->GetDocument(document);
|
|
|
|
if (nsnull != document) {
|
|
|
|
document->ContentChanged(content, nsnull);
|
|
|
|
NS_RELEASE(document);
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
void
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
if (mSizeFrozen) {
|
|
|
|
aDesiredSize.width = mRect.width;
|
|
|
|
aDesiredSize.height = mRect.height;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXX Don't create a view, because we want whatever is below the image
|
|
|
|
// to show through while the image is loading; Likewise for transparent
|
|
|
|
// images and broken images
|
|
|
|
//
|
|
|
|
// What we really want to do is to create a view, and indicate that the
|
|
|
|
// view has a transparent content area. Do this while it's loading,
|
|
|
|
// and then when it's fully loaded mark the view as opaque if the
|
|
|
|
// image is opaque.
|
|
|
|
//
|
|
|
|
// We can't use that approach yet, because currently the compositor doesn't
|
|
|
|
// support transparent views...
|
|
|
|
#if 0
|
1998-10-11 00:58:53 +00:00
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, this, mStyleContext, PR_TRUE);
|
1998-09-08 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
1998-11-21 04:04:41 +00:00
|
|
|
// Ask the image loader for the desired size
|
1998-09-26 18:36:59 +00:00
|
|
|
mImageLoader.GetDesiredSize(aPresContext, aReflowState,
|
|
|
|
this, UpdateImageFrame,
|
|
|
|
aDesiredSize);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00: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
|
|
|
|
nsImageFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsImageFrame::Reflow: aMaxSize=%d,%d",
|
|
|
|
aReflowState.maxSize.width, aReflowState.maxSize.height));
|
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
1998-11-21 04:04:41 +00:00
|
|
|
// If this is the initial reflow then set the image loader's
|
|
|
|
// source URL and base URL
|
|
|
|
if (eReflowReason_Initial == aReflowState.reason) {
|
|
|
|
nsAutoString src, base;
|
|
|
|
if ((NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", src)) &&
|
|
|
|
(src.Length() > 0)) {
|
|
|
|
mImageLoader.SetURL(src);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
|
|
|
mContent->GetAttribute(NS_HTML_BASE_HREF, base)) {
|
|
|
|
mImageLoader.SetBaseHREF(base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
GetDesiredSize(&aPresContext, aReflowState, aMetrics);
|
|
|
|
AddBordersAndPadding(&aPresContext, aReflowState, aMetrics, mBorderPadding);
|
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("exit nsImageFrame::Reflow: size=%d,%d",
|
|
|
|
aMetrics.width, aMetrics.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00: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 01:12:39 +00:00
|
|
|
// aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected
|
|
|
|
// into the rendering context before this is called (for performance). MMP
|
1998-09-08 22:34:40 +00:00
|
|
|
nscoord
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::MeasureString(const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nscoord aMaxWidth,
|
|
|
|
PRUint32& aMaxFit,
|
|
|
|
nsIRenderingContext& aContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nscoord totalWidth = 0;
|
|
|
|
nscoord spaceWidth;
|
1998-10-02 01:12:39 +00:00
|
|
|
aContext.GetWidth(' ', spaceWidth);
|
1998-09-08 22:34:40 +00: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 01:12:39 +00:00
|
|
|
aContext.GetWidth(aString, len, width);
|
1998-09-08 22:34:40 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::DisplayAltText(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsString& aAltText,
|
|
|
|
const nsRect& aRect)
|
1998-09-08 22:34:40 +00: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 02:08:25 +00:00
|
|
|
nsIFontMetrics* fm;
|
|
|
|
aRenderingContext.GetFontMetrics(fm);
|
1998-09-08 22:34:40 +00: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
|
1998-10-02 01:12:39 +00:00
|
|
|
nscoord width = MeasureString(str, strLen, aRect.width, maxFit, aRenderingContext);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
// Display the text
|
|
|
|
aRenderingContext.DrawString(str, maxFit, aRect.x, y, 0);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
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;
|
|
|
|
mHasCachedMargin = mHasCachedPadding = mHasCachedBorder = PR_FALSE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-09-22 03:34:44 +00:00
|
|
|
void
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::DisplayAltFeedback(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
PRInt32 aIconId)
|
1998-09-22 03:34:44 +00:00
|
|
|
{
|
|
|
|
// Display a recessed one pixel border in the inner area
|
1998-10-30 02:08:25 +00:00
|
|
|
PRBool clipState;
|
1998-09-22 03:34:44 +00:00
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(&aPresContext, inner);
|
|
|
|
|
1998-11-14 01:52:27 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext.GetScaledPixelsToTwips(p2t);
|
1998-09-22 03:34:44 +00:00
|
|
|
nsRecessedBorder recessedBorder(NSIntPixelsToTwips(1, p2t));
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, inner,
|
|
|
|
inner, recessedBorder, 0);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
aRenderingContext.PushState();
|
1998-10-30 02:08:25 +00:00
|
|
|
aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect, clipState);
|
1998-09-22 03:34:44 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Display the icon
|
1998-10-30 02:08:25 +00:00
|
|
|
nsIDeviceContext* dc;
|
|
|
|
aRenderingContext.GetDeviceContext(dc);
|
1998-09-22 03:34:44 +00:00
|
|
|
nsIImage* icon;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(dc->LoadIconImage(aIconId, icon))) {
|
|
|
|
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);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
|
|
|
nsAutoString altText;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("ALT", altText)) {
|
|
|
|
DisplayAltText(aPresContext, aRenderingContext, altText, inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-30 02:08:25 +00:00
|
|
|
aRenderingContext.PopState(clipState);
|
1998-09-22 03:34:44 +00:00
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
NS_METHOD
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
if ((0 == mRect.width) || (0 == mRect.height)) {
|
|
|
|
// Do not render when given a zero area. This avoids some useless
|
|
|
|
// scaling work while we wait for our image dimensions to arrive
|
|
|
|
// asynchronously.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
if (disp->mVisible) {
|
|
|
|
// First paint background and borders
|
|
|
|
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
|
|
|
|
|
|
|
|
nsIImage* image = mImageLoader.GetImage();
|
|
|
|
if (nsnull == image) {
|
1998-09-22 04:01:16 +00:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
|
|
|
// indicating the status
|
|
|
|
DisplayAltFeedback(aPresContext, aRenderingContext,
|
|
|
|
mImageLoader.GetLoadImageFailed() ? NS_ICON_BROKEN_IMAGE :
|
|
|
|
NS_ICON_LOADING_IMAGE);
|
1998-09-08 22:34:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now render the image into our inner area (the area without the
|
|
|
|
// borders and padding)
|
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(&aPresContext, inner);
|
|
|
|
if (mImageLoader.GetLoadImageFailed()) {
|
1998-11-14 01:52:27 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext.GetScaledPixelsToTwips(p2t);
|
1998-09-08 22:34:40 +00:00
|
|
|
inner.width = NSIntPixelsToTwips(image->GetWidth(), p2t);
|
|
|
|
inner.height = NSIntPixelsToTwips(image->GetHeight(), p2t);
|
|
|
|
}
|
|
|
|
aRenderingContext.DrawImage(image, inner);
|
|
|
|
|
|
|
|
if (GetShowFrameBorders()) {
|
|
|
|
nsIImageMap* map = GetImageMap();
|
|
|
|
if (nsnull != map) {
|
1998-10-30 02:08:25 +00:00
|
|
|
PRBool clipState;
|
1998-09-08 22:34:40 +00:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(inner.x, inner.y);
|
1998-10-30 02:08:25 +00:00
|
|
|
map->Draw(aPresContext, aRenderingContext);
|
|
|
|
aRenderingContext.PopState(clipState);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIImageMap*
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::GetImageMap()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
if (nsnull == mImageMap) {
|
|
|
|
nsAutoString usemap;
|
|
|
|
mContent->GetAttribute("usemap", usemap);
|
|
|
|
if (0 == usemap.Length()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIImageMap* map;
|
|
|
|
rv = hdoc->GetImageMap(usemap, &map);
|
|
|
|
NS_RELEASE(hdoc);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mImageMap = map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(mImageMap);
|
|
|
|
return mImageMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::TriggerLink(nsIPresContext& aPresContext,
|
|
|
|
const nsString& aURLSpec,
|
|
|
|
const nsString& aTargetSpec,
|
|
|
|
PRBool aClick)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nsILinkHandler* handler = nsnull;
|
|
|
|
aPresContext.GetLinkHandler(&handler);
|
|
|
|
if (nsnull != handler) {
|
|
|
|
if (aClick) {
|
1998-11-14 00:21:19 +00:00
|
|
|
handler->OnLinkClick(mContent, eLinkVerb_Replace, aURLSpec, aTargetSpec);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-11-14 00:21:19 +00:00
|
|
|
handler->OnOverLink(mContent, aURLSpec, aTargetSpec);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::IsServerImageMap()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nsAutoString ismap;
|
|
|
|
return NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("ismap", ismap);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::GetSuppress()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("suppress", s)) {
|
|
|
|
if (s.EqualsIgnoreCase("true")) {
|
|
|
|
return SUPPRESS;
|
|
|
|
} else if (s.EqualsIgnoreCase("false")) {
|
|
|
|
return DONT_SUPPRESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DEFAULT_SUPPRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX what should clicks on transparent pixels do?
|
|
|
|
NS_METHOD
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nsIImageMap* map;
|
|
|
|
aEventStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
map = GetImageMap();
|
|
|
|
if ((nsnull != map) || IsServerImageMap()) {
|
|
|
|
nsIURL* docURL = nsnull;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
mContent->GetDocument(doc);
|
|
|
|
if (nsnull != doc) {
|
|
|
|
docURL = doc->GetDocumentURL();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask map if the x,y coordinates are in a clickable area
|
|
|
|
float t2p = aPresContext.GetTwipsToPixels();
|
|
|
|
nsAutoString absURL, target, altText;
|
|
|
|
PRBool suppress;
|
|
|
|
if (nsnull != map) {
|
|
|
|
// Subtract out border and padding here so that we are looking
|
|
|
|
// at the right coordinates. Hit detection against area tags
|
|
|
|
// is done after the mouse wanders over the image, not over
|
|
|
|
// the image's borders.
|
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(&aPresContext, inner);
|
1998-11-20 06:31:55 +00:00
|
|
|
|
|
|
|
// XXX Event isn't in our local coordinate space like it should be...
|
|
|
|
nsIView* view;
|
|
|
|
GetView(view);
|
|
|
|
if (nsnull == view) {
|
|
|
|
nsPoint offset;
|
|
|
|
GetOffsetFromView(offset, view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
aEvent->point -= offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
PRInt32 x = NSTwipsToIntPixels((aEvent->point.x - inner.x), t2p);
|
|
|
|
PRInt32 y = NSTwipsToIntPixels((aEvent->point.y - inner.y), t2p);
|
|
|
|
nsresult r = map->IsInside(x, y, docURL, absURL, target, altText,
|
|
|
|
&suppress);
|
|
|
|
NS_IF_RELEASE(docURL);
|
|
|
|
NS_RELEASE(map);
|
|
|
|
if (NS_OK == r) {
|
|
|
|
// We hit a clickable area. Time to go somewhere...
|
|
|
|
PRBool clicked = PR_FALSE;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
|
|
|
aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
clicked = PR_TRUE;
|
|
|
|
}
|
|
|
|
TriggerLink(aPresContext, absURL, target, clicked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
suppress = GetSuppress();
|
|
|
|
nsAutoString baseURL;
|
|
|
|
mContent->GetAttribute(NS_HTML_BASE_HREF, baseURL);
|
|
|
|
nsAutoString src;
|
|
|
|
mContent->GetAttribute("src", src);
|
|
|
|
NS_MakeAbsoluteURL(docURL, baseURL, src, absURL);
|
|
|
|
|
|
|
|
// Note: We don't subtract out the border/padding here to remain
|
|
|
|
// compatible with navigator. [ick]
|
|
|
|
PRInt32 x = NSTwipsToIntPixels(aEvent->point.x, t2p);
|
|
|
|
PRInt32 y = NSTwipsToIntPixels(aEvent->point.y, t2p);
|
|
|
|
char cbuf[50];
|
|
|
|
PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", x, y);
|
|
|
|
absURL.Append(cbuf);
|
|
|
|
PRBool clicked = PR_FALSE;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
|
|
|
aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
clicked = PR_TRUE;
|
|
|
|
}
|
|
|
|
TriggerLink(aPresContext, absURL, target, clicked);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALL THROUGH
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Let default event handler deal with it
|
|
|
|
return nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::GetCursor(nsIPresContext& aPresContext,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRInt32& aCursor)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
//XXX This will need to be rewritten once we have content for areas
|
|
|
|
nsIImageMap* map = GetImageMap();
|
|
|
|
if (nsnull != map) {
|
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(&aPresContext, inner);
|
|
|
|
aCursor = NS_STYLE_CURSOR_DEFAULT;
|
|
|
|
float t2p = aPresContext.GetTwipsToPixels();
|
1998-11-20 06:31:55 +00:00
|
|
|
|
|
|
|
// XXX Event isn't in our local coordinate space like it should be...
|
|
|
|
nsPoint pt = aPoint;
|
|
|
|
nsIView* view;
|
|
|
|
GetView(view);
|
|
|
|
if (nsnull == view) {
|
|
|
|
nsPoint offset;
|
|
|
|
GetOffsetFromView(offset, view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
pt -= offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 x = NSTwipsToIntPixels((pt.x - inner.x), t2p);
|
|
|
|
PRInt32 y = NSTwipsToIntPixels((pt.y - inner.y), t2p);
|
1998-11-18 05:25:26 +00:00
|
|
|
if (NS_OK == map->IsInside(x, y)) {
|
1998-11-23 22:21:13 +00: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-08 22:34:40 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(map);
|
|
|
|
return NS_OK;
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
return nsFrame::GetCursor(aPresContext, aPoint, aCursor);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1998-09-29 23:48:07 +00:00
|
|
|
nsresult rv = nsLeafFrame::AttributeChanged(aPresContext, aChild,
|
|
|
|
aAttribute, aHint);
|
1998-09-28 21:22:31 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-29 23:48:07 +00:00
|
|
|
if (nsHTMLAtoms::src == aAttribute) {
|
1998-09-28 21:22:31 +00:00
|
|
|
nsAutoString oldSRC;
|
|
|
|
mImageLoader.GetURL(oldSRC);
|
|
|
|
nsAutoString newSRC;
|
|
|
|
|
|
|
|
aChild->GetAttribute("src", newSRC);
|
1998-09-08 22:34:40 +00:00
|
|
|
if (!oldSRC.Equals(newSRC)) {
|
|
|
|
mSizeFrozen = PR_TRUE;
|
1998-09-28 21:22:31 +00:00
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
char oldcbuf[100], newcbuf[100];
|
|
|
|
oldSRC.ToCString(oldcbuf, sizeof(oldcbuf));
|
|
|
|
newSRC.ToCString(newcbuf, sizeof(newcbuf));
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
1998-11-20 17:21:02 +00:00
|
|
|
("nsImageFrame::AttributeChanged: new image source; old='%s' new='%s'",
|
1998-09-08 22:34:40 +00:00
|
|
|
oldcbuf, newcbuf));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get rid of old image loader and start a new image load going
|
|
|
|
mImageLoader.DestroyLoader();
|
|
|
|
|
|
|
|
// Fire up a new image load request
|
|
|
|
PRIntn loadStatus;
|
|
|
|
mImageLoader.SetURL(newSRC);
|
1998-09-26 18:36:59 +00:00
|
|
|
mImageLoader.StartLoadImage(aPresContext, this, nsnull,
|
|
|
|
PR_FALSE, loadStatus);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
1998-11-20 17:21:02 +00:00
|
|
|
("nsImageFrame::AttributeChanged: loadImage status=%x",
|
1998-09-28 21:22:31 +00:00
|
|
|
loadStatus));
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
// If the image is already ready then we need to trigger a
|
|
|
|
// redraw because the image loader won't.
|
|
|
|
if (loadStatus & NS_IMAGE_LOAD_STATUS_IMAGE_READY) {
|
|
|
|
// XXX Stuff this into a method on nsIPresShell/Context
|
|
|
|
nsRect bounds;
|
|
|
|
nsPoint offset;
|
|
|
|
nsIView* view;
|
|
|
|
GetOffsetFromView(offset, view);
|
|
|
|
nsIViewManager* vm;
|
|
|
|
view->GetViewManager(vm);
|
|
|
|
bounds.x = offset.x;
|
|
|
|
bounds.y = offset.y;
|
|
|
|
bounds.width = mRect.width;
|
|
|
|
bounds.height = mRect.height;
|
|
|
|
vm->UpdateView(view, bounds, 0);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-25 16:35:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|