gecko-dev/layout/generic/nsImageFrame.cpp

773 строки
24 KiB
C++
Исходник Обычный вид История

1998-09-09 02:34:40 +04: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 "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"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsHTMLContainerFrame.h"
1998-09-09 02:34:40 +04:00
#include "prprf.h"
#include "nsIFontMetrics.h"
#include "nsCSSRendering.h"
#include "nsIDOMHTMLImageElement.h"
#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"
#include "nsIDOMHTMLMapElement.h"
#include "nsIStyleSet.h"
1998-09-09 02:34:40 +04:00
#ifdef DEBUG
#undef NOISY_IMAGE_LOADING
#else
#undef NOISY_IMAGE_LOADING
#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
NS_NewImageFrame(nsIFrame*& aResult)
1998-09-09 02:34:40 +04:00
{
nsImageFrame* frame = new nsImageFrame;
1998-09-09 02:34:40 +04:00
if (nsnull == frame) {
return NS_ERROR_OUT_OF_MEMORY;
}
aResult = frame;
return NS_OK;
}
nsImageFrame::~nsImageFrame()
1998-09-09 02:34:40 +04:00
{
}
NS_METHOD
nsImageFrame::DeleteFrame(nsIPresContext& aPresContext)
1998-09-09 02:34:40 +04:00
{
NS_IF_RELEASE(mImageMap);
// Release image loader first so that it's refcnt can go to zero
mImageLoader.StopAllLoadImages(&aPresContext);
1998-09-09 02:34:40 +04:00
return nsLeafFrame::DeleteFrame(aPresContext);
}
NS_IMETHODIMP
nsImageFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent,
aContext, aPrevInFlow);
1999-02-27 03:57:04 +03:00
// See if we have a SRC attribute
PRBool sourcePresent = PR_FALSE;
nsAutoString src;
nsresult ca;
ca = mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, src);
if ((NS_CONTENT_ATTR_HAS_VALUE == ca) && (src.Length() > 0)) {
sourcePresent = PR_TRUE;
1999-02-27 03:57:04 +03:00
}
else {
// XXX ick: this should only work for OBJECT tags
ca = mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::data, src);
if ((NS_CONTENT_ATTR_HAS_VALUE == ca) && (src.Length() > 0)) {
sourcePresent = PR_TRUE;
}
1999-02-27 03:57:04 +03:00
}
// Set the image loader's source URL and base URL
if (sourcePresent) {
nsIURL* baseURL = nsnull;
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);
if (NS_SUCCEEDED(rv)) {
doc->GetBaseURL(baseURL);
NS_RELEASE(doc);
}
}
mImageLoader.Init(this, UpdateImageFrame, nsnull, baseURL, src);
NS_IF_RELEASE(baseURL);
}
return rv;
}
nsresult
nsImageFrame::UpdateImageFrame(nsIPresContext* aPresContext,
nsHTMLImageLoader* aLoader,
nsIFrame* aFrame,
void* aClosure,
PRUint32 aStatus)
{
nsImageFrame* frame = (nsImageFrame*) aFrame;
return frame->UpdateImage(aPresContext, aStatus);
}
nsresult
nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus)
1998-09-26 22:36:59 +04:00
{
#ifdef NOISY_IMAGE_LOADING
ListTag(stdout);
printf(": UpdateImage: status=%x\n", aStatus);
#endif
if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) {
// We failed to load the image. Notify the pres shell
nsIPresShell* presShell;
aPresContext->GetShell(&presShell);
if (presShell) {
presShell->CantRenderReplacedElement(aPresContext, this);
NS_RELEASE(presShell);
}
}
else if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
1998-09-26 22:36:59 +04:00
// Now that the size is available, trigger a content-changed reflow
if (nsnull != mContent) {
1998-09-26 22:36:59 +04:00
nsIDocument* document = nsnull;
mContent->GetDocument(document);
1998-09-26 22:36:59 +04:00
if (nsnull != document) {
document->ContentChanged(mContent, nsnull);
1998-09-26 22:36:59 +04:00
NS_RELEASE(document);
}
}
}
return NS_OK;
}
1998-09-09 02:34:40 +04:00
void
nsImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
1998-09-09 02:34:40 +04:00
{
mImageLoader.GetDesiredSize(aPresContext, &aReflowState, aDesiredSize);
1998-09-09 02:34:40 +04: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.availableWidth, aReflowState.availableHeight));
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
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-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
// aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected
// into the rendering context before this is called (for performance). MMP
void
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;
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;
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
nsImageFrame::DisplayAltText(nsIPresContext& aPresContext,
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
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
MeasureString(str, strLen, aRect.width, maxFit, aRenderingContext);
1998-09-09 02:34:40 +04:00
// Display the text
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);
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;
}
};
void
nsImageFrame::DisplayAltFeedback(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
PRInt32 aIconId)
{
// Display a recessed one pixel border in the inner area
PRBool clipState;
nsRect inner;
GetInnerArea(&aPresContext, inner);
1998-11-14 04:52:27 +03:00
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
nsRecessedBorder recessedBorder(NSIntPixelsToTwips(1, p2t));
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, inner,
inner, recessedBorder, mStyleContext, 0);
// Adjust the inner rect to account for the one pixel recessed border,
// and a six pixel padding on each edge
inner.Deflate(NSIntPixelsToTwips(7, p2t), NSIntPixelsToTwips(7, p2t));
if (inner.IsEmpty()) {
return;
}
// Clip so we don't render outside the inner rect
aRenderingContext.PushState();
aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect, clipState);
// Display the icon
nsIDeviceContext* dc;
aRenderingContext.GetDeviceContext(dc);
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);
// 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)) {
DisplayAltText(aPresContext, aRenderingContext, altText, inner);
}
}
aRenderingContext.PopState(clipState);
}
1998-09-09 02:34:40 +04:00
NS_METHOD
nsImageFrame::Paint(nsIPresContext& aPresContext,
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);
1998-09-09 02:34:40 +04:00
if (disp->mVisible) {
1999-04-10 21:32:33 +04:00
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
aRenderingContext.PushState();
SetClipRect(aRenderingContext);
}
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
nsIImage* image = mImageLoader.GetImage();
if (nsnull == image) {
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
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
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 {
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;
GetInnerArea(&aPresContext, inner);
1999-04-10 21:32:33 +04:00
if (mImageLoader.GetLoadImageFailed()) {
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
inner.width = NSIntPixelsToTwips(image->GetWidth(), p2t);
inner.height = NSIntPixelsToTwips(image->GetHeight(), p2t);
}
aRenderingContext.DrawImage(image, inner);
1998-09-09 02:34:40 +04:00
}
1999-04-10 21:32:33 +04:00
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
GetShowFrameBorders()) {
nsImageMap* map = GetImageMap();
if (nsnull != map) {
nsRect inner;
GetInnerArea(&aPresContext, inner);
PRBool clipState;
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
aRenderingContext.PushState();
aRenderingContext.Translate(inner.x, inner.y);
map->Draw(aPresContext, aRenderingContext);
aRenderingContext.PopState(clipState);
}
}
}
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
PRBool clipState;
aRenderingContext.PopState(clipState);
1998-09-09 02:34:40 +04:00
}
}
return NS_OK;
}
1999-01-09 03:13:19 +03:00
nsImageMap*
nsImageFrame::GetImageMap()
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;
}
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)) {
mImageMap = new nsImageMap();
if (nsnull != mImageMap) {
mImageMap->Init(map);
}
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
nsImageFrame::TriggerLink(nsIPresContext& aPresContext,
const nsString& aURLSpec,
const nsString& aTargetSpec,
PRBool aClick)
1998-09-09 02:34:40 +04:00
{
nsILinkHandler* handler = nsnull;
aPresContext.GetLinkHandler(&handler);
if (nsnull != handler) {
if (aClick) {
1999-04-22 03:35:12 +04:00
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
}
NS_RELEASE(handler);
1998-09-09 02:34:40 +04:00
}
}
PRBool
nsImageFrame::IsServerImageMap()
1998-09-09 02:34:40 +04:00
{
nsAutoString ismap;
1998-12-20 04:21:23 +03:00
return NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::ismap, ismap);
1998-09-09 02:34:40 +04:00
}
PRIntn
nsImageFrame::GetSuppress()
1998-09-09 02:34:40 +04:00
{
nsAutoString s;
1998-12-20 04:21:23 +03: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;
}
// XXX what should clicks on transparent pixels do?
NS_METHOD
nsImageFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
1998-09-09 02:34:40 +04:00
{
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:
map = GetImageMap();
if ((nsnull != map) || IsServerImageMap()) {
// Ask map if the x,y coordinates are in a clickable area
float t2p;
aPresContext.GetTwipsToPixels(&t2p);
1998-09-09 02:34:40 +04:00
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);
// 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-09 02:34:40 +04:00
PRInt32 x = NSTwipsToIntPixels((aEvent->point.x - inner.x), t2p);
PRInt32 y = NSTwipsToIntPixels((aEvent->point.y - inner.y), t2p);
nsIURL* docURL = nsnull;
nsIDocument* doc = nsnull;
mContent->GetDocument(doc);
if (nsnull != doc) {
docURL = doc->GetDocumentURL();
NS_RELEASE(doc);
}
NS_ASSERTION(nsnull != docURL, "nsIDocument->GetDocumentURL() returning nsnull");
PRBool inside = PR_FALSE;
if (nsnull != docURL) {
inside = map->IsInside(x, y, docURL, absURL, target, altText,
&suppress);
}
1998-09-09 02:34:40 +04:00
NS_IF_RELEASE(docURL);
1999-01-09 03:13:19 +03:00
if (inside) {
1998-09-09 02:34:40 +04:00
// We hit a clickable area. Time to go somewhere...
PRBool clicked = PR_FALSE;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
aEventStatus = nsEventStatus_eConsumeDoDefault;
1998-09-09 02:34:40 +04:00
clicked = PR_TRUE;
}
TriggerLink(aPresContext, absURL, target, clicked);
}
}
else {
suppress = GetSuppress();
nsIURL* 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);
}
}
1998-09-09 02:34:40 +04:00
nsAutoString src;
nsString empty;
1998-12-20 04:21:23 +03:00
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, src);
NS_MakeAbsoluteURL(baseURL, empty, src, absURL);
NS_IF_RELEASE(baseURL);
1998-09-09 02:34:40 +04:00
// 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_eConsumeDoDefault;
1998-09-09 02:34:40 +04:00
clicked = PR_TRUE;
}
TriggerLink(aPresContext, absURL, target, clicked);
}
break;
}
default:
break;
1998-09-09 02:34:40 +04:00
}
return nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
1998-09-09 02:34:40 +04:00
}
NS_METHOD
nsImageFrame::GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor)
1998-09-09 02:34:40 +04:00
{
//XXX This will need to be rewritten once we have content for areas
1999-01-09 03:13:19 +03:00
nsImageMap* map = GetImageMap();
if (nsnull != map) {
nsRect inner;
GetInnerArea(&aPresContext, inner);
aCursor = NS_STYLE_CURSOR_DEFAULT;
float t2p;
aPresContext.GetTwipsToPixels(&t2p);
// 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);
1999-01-09 03:13:19 +03:00
if (map->IsInside(x, y)) {
// 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
}
return NS_OK;
1998-09-09 02:34:40 +04:00
}
return nsFrame::GetCursor(aPresContext, aPoint, aCursor);
1998-09-09 02:34:40 +04:00
}
NS_IMETHODIMP
nsImageFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute,
PRInt32 aHint)
1998-09-09 02:34:40 +04:00
{
nsresult rv = nsLeafFrame::AttributeChanged(aPresContext, aChild,
aAttribute, aHint);
if (NS_OK != rv) {
return rv;
}
if (nsHTMLAtoms::src == aAttribute) {
nsAutoString oldSRC, newSRC;
mImageLoader.GetURLSpec(oldSRC);
1998-12-20 04:21:23 +03:00
aChild->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, newSRC);
1998-09-09 02:34:40 +04:00
if (!oldSRC.Equals(newSRC)) {
#ifdef NOISY_IMAGE_LOADING
ListTag(stdout);
printf(": new image source; old='");
fputs(oldSRC, stdout);
printf("' new='");
fputs(newSRC, stdout);
printf("'\n");
1998-09-09 02:34:40 +04:00
#endif
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.
Invalidate(nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);
}
}
else {
// Force a reflow when the image size isn't already known
if (nsnull != mContent) {
nsIDocument* document = nsnull;
mContent->GetDocument(document);
if (nsnull != document) {
document->ContentChanged(mContent, nsnull);
NS_RELEASE(document);
}
}
1998-09-09 02:34:40 +04:00
}
}
}
return NS_OK;
}