2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
2002-11-20 03:44:26 +03:00
|
|
|
#include "nsPrintfCString.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIDocument.h"
|
2002-11-20 03:44:26 +03:00
|
|
|
#include "nsINodeInfo.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#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"
|
2001-03-22 04:38:35 +03:00
|
|
|
#include "nsILoadGroup.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
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"
|
2001-04-18 04:14:34 +04:00
|
|
|
#include "nsImageMapUtils.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"
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgILoader.h"
|
|
|
|
|
2001-07-11 09:44:12 +04:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "plevent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2001-07-11 09:44:12 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2001-11-07 08:02:42 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2002-12-11 17:05:41 +03:00
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.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
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
2001-11-07 08:02:42 +03:00
|
|
|
#undef NOISY_ICON_LOADING
|
1999-04-14 01:51:20 +04:00
|
|
|
#else
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
2001-11-07 08:02:42 +03:00
|
|
|
#undef NOISY_ICON_LOADING
|
1998-11-14 00:31:50 +03:00
|
|
|
#endif
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// values for image loading icons
|
|
|
|
#define NS_ICON_LOADING_IMAGE (0)
|
|
|
|
#define NS_ICON_BROKEN_IMAGE (1)
|
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// sizes (pixels) for image icon, padding and border frame
|
|
|
|
#define ICON_SIZE (16)
|
|
|
|
#define ICON_PADDING (3)
|
|
|
|
#define ALT_BORDER_WIDTH (1)
|
|
|
|
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Default alignment value (so we can tell an unset value from a set value)
|
|
|
|
#define ALIGN_UNSET PRUint8(-1)
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// static icon information: initialized in Init and de-initialized in Destroy
|
|
|
|
// - created if null, deleted if refcount goes to 0
|
|
|
|
nsImageFrame::IconLoad* nsImageFrame::mIconLoad = nsnull;
|
|
|
|
|
|
|
|
// test if the width and height are fixed, looking at the style data
|
|
|
|
static PRBool HaveFixedSize(const struct nsStylePosition& aStylePosition)
|
|
|
|
{
|
|
|
|
// check the width and height values in the reflow state's style struct
|
|
|
|
// - if width and height are specified as either coord or percentage, then
|
|
|
|
// the size of the image frame is constrained
|
|
|
|
nsStyleUnit widthUnit = aStylePosition.mWidth.GetUnit();
|
|
|
|
nsStyleUnit heightUnit = aStylePosition.mHeight.GetUnit();
|
|
|
|
|
|
|
|
return ((widthUnit == eStyleUnit_Coord ||
|
|
|
|
widthUnit == eStyleUnit_Percent) &&
|
|
|
|
(heightUnit == eStyleUnit_Coord ||
|
|
|
|
heightUnit == eStyleUnit_Percent));
|
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
// use the data in the reflow state to decide if the image has a constrained size
|
|
|
|
// (i.e. width and height that are based on the containing block size and not the image size)
|
|
|
|
// so we can avoid animated GIF related reflows
|
2001-11-07 08:02:42 +03:00
|
|
|
inline PRBool HaveFixedSize(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aReflowState.mStylePosition, "crappy reflowState - null stylePosition");
|
2002-11-07 05:50:39 +03:00
|
|
|
// when an image has percent css style height or width, but mComputedHeight
|
|
|
|
// or mComputedWidth of reflow state is NS_UNCONSTRAINEDSIZE
|
|
|
|
// it needs to return PR_FALSE to cause an incremental reflow later
|
|
|
|
// if an image is inside table like bug 156731 simple testcase III,
|
|
|
|
// during pass 1 reflow, mComputedWidth is NS_UNCONSTRAINEDSIZE
|
|
|
|
// in pass 2 reflow, mComputedWidth is 0, it also needs to return PR_FALSE
|
|
|
|
// see bug 156731
|
|
|
|
nsStyleUnit heightUnit = (*(aReflowState.mStylePosition)).mHeight.GetUnit();
|
|
|
|
nsStyleUnit widthUnit = (*(aReflowState.mStylePosition)).mWidth.GetUnit();
|
|
|
|
return ((eStyleUnit_Percent == heightUnit && NS_UNCONSTRAINEDSIZE == aReflowState.mComputedHeight) ||
|
|
|
|
(eStyleUnit_Percent == widthUnit && (NS_UNCONSTRAINEDSIZE == aReflowState.mComputedWidth ||
|
|
|
|
0 == aReflowState.mComputedWidth)))
|
|
|
|
? PR_FALSE
|
|
|
|
: HaveFixedSize(*(aReflowState.mStylePosition));
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
nsImageFrame::GetImageLoad(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
if (aRequest == mLoads[0].mRequest)
|
|
|
|
return 0;
|
|
|
|
else if (aRequest == mLoads[1].mRequest)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
NS_ASSERTION((aRequest == mLoads[0].mRequest &&
|
2001-10-14 05:17:08 +04:00
|
|
|
aRequest == mLoads[1].mRequest), "Failure to figure out which imgIRequest this is!");
|
2001-10-06 09:08:16 +04:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
nsImageFrame::nsImageFrame() :
|
2003-02-25 01:20:26 +03:00
|
|
|
mIntrinsicSize(0, 0)
|
2000-04-19 18:00:11 +04:00
|
|
|
{
|
2001-03-06 03:47:46 +03:00
|
|
|
// Size is constrained if we have a width and height.
|
|
|
|
// - Set in reflow in case the attributes are changed
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_FAILUREREPLACE;
|
2000-04-19 18:00:11 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
|
|
|
*aInstancePtr = nsnull;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIImageFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
|
|
|
|
return NS_OK;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
|
|
|
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsImageFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsImageFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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.
|
2001-05-04 10:29:59 +04:00
|
|
|
if(mImageMap) {
|
|
|
|
mImageMap->Destroy();
|
|
|
|
NS_RELEASE(mImageMap);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
for (int i=0; i != 2; ++i) {
|
2001-10-06 09:08:16 +04:00
|
|
|
if (mLoads[i].mRequest) {
|
|
|
|
mLoads[i].mRequest->Cancel(NS_ERROR_FAILURE);
|
|
|
|
mLoads[i].mRequest = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
|
|
|
if (mListener)
|
|
|
|
NS_REINTERPRET_CAST(nsImageListener*, mListener.get())->SetFrame(nsnull);
|
|
|
|
|
|
|
|
mListener = nsnull;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// check / cleanup the IconLoads singleton
|
|
|
|
if (mIconLoad) {
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "Releasing IconLoad (%p)\n", this);
|
|
|
|
#endif
|
|
|
|
if (mIconLoad->Release()) {
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "Deleting IconLoad (%p)\n", this);
|
|
|
|
#endif
|
|
|
|
delete mIconLoad;
|
|
|
|
mIconLoad = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
return nsSplittableFrame::Destroy(aPresContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03: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,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aContext,
|
1999-02-25 06:27:57 +03:00
|
|
|
nsIFrame* aPrevInFlow)
|
1998-12-29 06:38:16 +03:00
|
|
|
{
|
2001-11-01 18:31:13 +03:00
|
|
|
nsresult rv = nsSplittableFrame::Init(aPresContext, aContent, aParent,
|
|
|
|
aContext, aPrevInFlow);
|
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;
|
2002-05-21 02:47:02 +04:00
|
|
|
ca = mContent->GetAttr(kNameSpaceID_None, 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)
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, src);
|
1999-05-06 03:40:21 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(tag);
|
1999-02-27 03:57:04 +03:00
|
|
|
}
|
|
|
|
|
2003-02-25 01:20:26 +03:00
|
|
|
mState &= ~IMAGE_INITIALLOADCOMPLETED;
|
|
|
|
mState |= IMAGE_CANSENDLOADEVENT;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
LoadIcons(aPresContext);
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mRequest = do_CreateInstance("@mozilla.org/image/request;1");
|
|
|
|
rv = LoadImage(src, aPresContext, mLoads[0].mRequest); // if the image was found in the cache,
|
|
|
|
// it is possible that LoadImage will result in
|
|
|
|
// a call to OnStartContainer()
|
2001-03-22 04:38:35 +03:00
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnStartDecode(imgIRequest *aRequest, nsIPresContext *aPresContext)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnStartContainer(imgIRequest *aRequest, nsIPresContext *aPresContext, imgIContainer *aImage)
|
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_INITIALLOADCOMPLETED;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, PR_FALSE)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
int whichLoad = GetImageLoad(aRequest);
|
|
|
|
if (whichLoad == -1) return NS_ERROR_FAILURE;
|
|
|
|
struct ImageLoad *load= &mLoads[whichLoad];
|
|
|
|
|
2001-04-17 02:02:39 +04:00
|
|
|
if (aImage)
|
|
|
|
{
|
|
|
|
/* Get requested animation policy from the pres context:
|
|
|
|
* normal = 0
|
|
|
|
* one frame = 1
|
|
|
|
* one loop = 2
|
|
|
|
*/
|
2001-11-14 16:59:08 +03:00
|
|
|
PRUint16 animateMode = imgIContainer::kNormalAnimMode; //default value
|
2001-04-17 02:02:39 +04:00
|
|
|
nsresult rv = aPresContext->GetImageAnimationMode(&animateMode);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
aImage->SetAnimationMode(animateMode);
|
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
nscoord w, h;
|
|
|
|
aImage->GetWidth(&w);
|
|
|
|
aImage->GetHeight(&h);
|
|
|
|
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
|
|
|
|
nsSize newsize(NSIntPixelsToTwips(w, p2t), NSIntPixelsToTwips(h, p2t));
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
if (load->mIntrinsicSize != newsize) {
|
|
|
|
load->mIntrinsicSize = newsize;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
if (load->mIntrinsicSize.width != 0 && load->mIntrinsicSize.height != 0)
|
|
|
|
load->mTransform.SetToScale((float(mComputedSize.width) / float(load->mIntrinsicSize.width)),
|
|
|
|
(float(mComputedSize.height) / float(load->mIntrinsicSize.height)));
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-02-25 01:20:26 +03:00
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED)) {
|
2001-04-15 06:13:49 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
|
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
2003-02-25 01:20:26 +03:00
|
|
|
if (mParent && presShell && (mState & IMAGE_GOTINITIALREFLOW) && whichLoad == 0) { // don't reflow if we havn't gotten the inital reflow yet
|
2001-03-22 04:38:35 +03:00
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
2001-04-15 06:13:49 +04:00
|
|
|
mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnStartFrame(imgIRequest *aRequest, nsIPresContext *aPresContext, gfxIImageFrame *aFrame)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnDataAvailable(imgIRequest *aRequest, nsIPresContext *aPresContext, gfxIImageFrame *aFrame, const nsRect *aRect)
|
|
|
|
{
|
2001-04-15 06:13:49 +04:00
|
|
|
// XXX do we need to make sure that the reflow from the OnStartContainer has been
|
2001-03-22 04:38:35 +03:00
|
|
|
// processed before we start calling invalidate
|
|
|
|
|
2001-04-04 12:23:14 +04:00
|
|
|
if (!aRect)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, PR_FALSE)) {
|
|
|
|
if (!aRect->IsEmpty()) {
|
|
|
|
Invalidate(aPresContext, *aRect, PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
int whichLoad = GetImageLoad(aRequest);
|
|
|
|
if (whichLoad == -1) return NS_ERROR_FAILURE;
|
|
|
|
if (whichLoad != 0) return NS_OK;
|
|
|
|
struct ImageLoad *load= &mLoads[whichLoad];
|
|
|
|
|
|
|
|
|
2001-04-04 12:23:14 +04:00
|
|
|
nsRect r(aRect->x, aRect->y, aRect->width, aRect->height);
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
2001-04-04 12:23:14 +04:00
|
|
|
r.x = NSIntPixelsToTwips(r.x, p2t);
|
|
|
|
r.y = NSIntPixelsToTwips(r.y, p2t);
|
|
|
|
r.width = NSIntPixelsToTwips(r.width, p2t);
|
|
|
|
r.height = NSIntPixelsToTwips(r.height, p2t);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
load->mTransform.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-06-26 02:12:15 +04:00
|
|
|
r.x += mBorderPadding.left;
|
|
|
|
r.y += mBorderPadding.top;
|
|
|
|
|
2001-11-06 04:44:20 +03:00
|
|
|
if (whichLoad == 0 && !r.IsEmpty())
|
2001-10-06 09:08:16 +04:00
|
|
|
Invalidate(aPresContext, r, PR_FALSE);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnStopFrame(imgIRequest *aRequest, nsIPresContext *aPresContext, gfxIImageFrame *aFrame)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::OnStopContainer(imgIRequest *aRequest, nsIPresContext *aPresContext, imgIContainer *aImage)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-11 09:44:12 +04:00
|
|
|
static void PR_CALLBACK
|
|
|
|
HandleImagePLEvent(nsIContent *aContent, PRUint32 aMessage, PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
NS_ERROR("null or non-DOM node passed to HandleImagePLEvent!");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> dom_doc;
|
|
|
|
node->GetOwnerDocument(getter_AddRefs(dom_doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
|
|
|
|
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> pres_shell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(pres_shell));
|
|
|
|
|
|
|
|
if (!pres_shell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pres_context;
|
|
|
|
pres_shell->GetPresContext(getter_AddRefs(pres_context));
|
|
|
|
|
|
|
|
if (!pres_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = aMessage;
|
|
|
|
|
|
|
|
aContent->HandleDOMEvent(pres_context, &event, nsnull, aFlags, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
HandleImageOnloadPLEvent(PLEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsIContent *content = (nsIContent *)PL_GetEventOwner(aEvent);
|
|
|
|
|
|
|
|
HandleImagePLEvent(content, NS_IMAGE_LOAD,
|
|
|
|
NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_CANT_BUBBLE);
|
|
|
|
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
HandleImageOnerrorPLEvent(PLEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsIContent *content = (nsIContent *)PL_GetEventOwner(aEvent);
|
|
|
|
|
|
|
|
HandleImagePLEvent(content, NS_IMAGE_ERROR, NS_EVENT_FLAG_INIT);
|
|
|
|
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
DestroyImagePLEvent(PLEvent* aEvent)
|
|
|
|
{
|
|
|
|
delete aEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire off a PLEvent that'll asynchronously call the image elements
|
|
|
|
// onload handler once handled. This is needed since the image library
|
|
|
|
// can't decide if it wants to call it's observer methods
|
|
|
|
// synchronously or asynchronously. If an image is loaded from the
|
|
|
|
// cache the notifications come back synchronously, but if the image
|
2002-12-14 23:18:56 +03:00
|
|
|
// is loaded from the network the notifications come back
|
2001-07-11 09:44:12 +04:00
|
|
|
// asynchronously.
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageFrame::FireDOMEvent(PRUint32 aMessage)
|
|
|
|
{
|
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventQueueService> event_service =
|
|
|
|
do_GetService(kEventQueueServiceCID);
|
|
|
|
|
|
|
|
if (!event_service) {
|
|
|
|
NS_WARNING("Failed to get event queue service");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventQueue> event_queue;
|
|
|
|
|
|
|
|
event_service->GetThreadEventQueue(NS_CURRENT_THREAD,
|
|
|
|
getter_AddRefs(event_queue));
|
|
|
|
|
|
|
|
if (!event_queue) {
|
|
|
|
NS_WARNING("Failed to get event queue from service");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLEvent *event = new PLEvent;
|
|
|
|
|
|
|
|
if (!event) {
|
|
|
|
// Out of memory, but none of our callers care, so just warn and
|
|
|
|
// don't fire the event
|
|
|
|
|
|
|
|
NS_WARNING("Out of memory?");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHandleEventProc f;
|
|
|
|
|
|
|
|
switch (aMessage) {
|
|
|
|
case NS_IMAGE_LOAD :
|
|
|
|
f = (PLHandleEventProc)::HandleImageOnloadPLEvent;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case NS_IMAGE_ERROR :
|
|
|
|
f = (PLHandleEventProc)::HandleImageOnerrorPLEvent;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Huh, I don't know how to fire this type of event?!");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PL_InitEvent(event, mContent, f, (PLDestroyEventProc)::DestroyImagePLEvent);
|
|
|
|
|
|
|
|
// The event owns the content pointer now.
|
|
|
|
NS_ADDREF(mContent);
|
|
|
|
|
|
|
|
event_queue->PostEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
NS_IMETHODIMP nsImageFrame::OnStopDecode(imgIRequest *aRequest, nsIPresContext *aPresContext, nsresult aStatus, const PRUnichar *aStatusArg)
|
|
|
|
{
|
2001-04-15 06:13:49 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
// check to see if an image error occurred
|
|
|
|
PRBool imageFailedToLoad = PR_FALSE;
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, NS_SUCCEEDED(aStatus))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
int whichLoad = GetImageLoad(aRequest);
|
|
|
|
|
|
|
|
if (whichLoad == -1) return NS_ERROR_FAILURE;
|
|
|
|
|
2001-10-21 04:12:53 +04:00
|
|
|
if (whichLoad == 1) {
|
2001-10-06 09:08:16 +04:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
mLoads[0].mRequest->Cancel(NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
mLoads[0].mRequest = mLoads[1].mRequest;
|
|
|
|
mLoads[0].mIntrinsicSize = mLoads[1].mIntrinsicSize;
|
2001-10-06 09:08:16 +04:00
|
|
|
// XXX i don't think we always want to set this.
|
2001-10-14 05:17:08 +04:00
|
|
|
mLoads[0].mTransform = mLoads[1].mTransform;
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
mLoads[1].mRequest = nsnull;
|
2001-10-06 09:08:16 +04:00
|
|
|
|
|
|
|
} else {
|
2002-06-19 01:28:53 +04:00
|
|
|
// load failed, we need to reset mLoads[0] to get an broken icon
|
|
|
|
// since the src attribute changed
|
|
|
|
mLoads[0].mRequest = nsnull;
|
2001-10-14 05:17:08 +04:00
|
|
|
mLoads[1].mRequest = nsnull;
|
2002-06-19 01:28:53 +04:00
|
|
|
imageFailedToLoad = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-25 01:20:26 +03:00
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED) && (mLoads[0].mIntrinsicSize != mIntrinsicSize)) {
|
2002-06-19 01:28:53 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
|
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
2003-02-25 01:20:26 +03:00
|
|
|
if (mParent && presShell && (mState & IMAGE_GOTINITIALREFLOW)) { // don't reflow if we havn't gotten the inital reflow yet
|
2002-06-19 01:28:53 +04:00
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsSize s;
|
|
|
|
GetSize(s);
|
|
|
|
nsRect r(0,0, s.width, s.height);
|
|
|
|
if (!r.IsEmpty()) {
|
|
|
|
Invalidate(aPresContext, r, PR_FALSE);
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (NS_FAILED(aStatus)) {
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
if (whichLoad == 0 || !mLoads[0].mRequest) {
|
2001-10-14 05:17:08 +04:00
|
|
|
imageFailedToLoad = PR_TRUE;
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// if src failed to load, determine how to handle it:
|
|
|
|
// - either render the ALT text in this frame, or let the presShell handle it
|
2001-05-21 01:21:44 +04:00
|
|
|
if (imageFailedToLoad && presShell) {
|
2003-02-25 01:20:26 +03:00
|
|
|
if (mState & IMAGE_FAILUREREPLACE) {
|
2001-11-07 08:02:42 +03:00
|
|
|
// first check for image map
|
2001-04-15 06:13:49 +04:00
|
|
|
nsAutoString usemap;
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap);
|
2001-04-15 06:13:49 +04:00
|
|
|
if (usemap.IsEmpty()) {
|
2001-11-07 08:02:42 +03:00
|
|
|
// check if we want to honor the ALT text in the IMG frame, or let the preShell make it into inline text
|
2002-03-26 23:14:05 +03:00
|
|
|
// - if QuirksMode, and the IMG has a size, then render the ALT text in the IMG frame
|
2001-11-07 08:02:42 +03:00
|
|
|
// UNLESS there is a pref set to force inline alt text
|
|
|
|
PRBool useSizedBox = PR_FALSE;
|
|
|
|
PRBool prefForceInlineAltText = mIconLoad ? mIconLoad->mPrefForceInlineAltText : PR_FALSE;
|
|
|
|
|
|
|
|
// check if we have fixed size
|
|
|
|
const nsStylePosition* stylePosition =
|
|
|
|
(const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position);
|
|
|
|
NS_ASSERTION(stylePosition, "null style position: frame is corrupted");
|
|
|
|
|
|
|
|
// check for quirks mode
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// check for being in Composer: if we are, we always show the size-box
|
|
|
|
PRBool forceIcon = PR_FALSE;
|
|
|
|
|
|
|
|
// check for style property that indicates the icon should always be shown
|
|
|
|
const nsStyleUIReset* styleData;
|
|
|
|
GetStyleData(eStyleStruct_UIReset, (const nsStyleStruct*&) styleData);
|
|
|
|
if (styleData->mForceBrokenImageIcon) {
|
|
|
|
forceIcon = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrap it all up: use the size box if
|
|
|
|
// - in editor
|
|
|
|
// - not forcing inline alt text, have fixed size, in quirks mode, image not blocked
|
|
|
|
useSizedBox = forceIcon ||
|
|
|
|
(!prefForceInlineAltText &&
|
|
|
|
HaveFixedSize(*stylePosition) &&
|
|
|
|
mode == eCompatibility_NavQuirks &&
|
2003-02-25 01:20:26 +03:00
|
|
|
!(mState & IMAGE_BLOCKED));
|
2001-11-07 08:02:42 +03:00
|
|
|
|
|
|
|
if (!useSizedBox) {
|
|
|
|
// let the presShell handle converting this into the inline alt text frame
|
|
|
|
presShell->CantRenderReplacedElement(aPresContext, this);
|
|
|
|
} else {
|
|
|
|
// we are handling it
|
|
|
|
// invalidate the icon area (it may change states)
|
|
|
|
InvalidateIcon(aPresContext);
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
2001-05-21 04:02:10 +04:00
|
|
|
}
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_FAILUREREPLACE;
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// After these DOM events are fired its possible that this frame may be deleted. As a result
|
|
|
|
// the code should not attempt to access any of the frames internal data after this point.
|
|
|
|
if (presShell) {
|
|
|
|
if (imageFailedToLoad) {
|
|
|
|
// Send error event
|
2001-07-11 09:44:12 +04:00
|
|
|
FireDOMEvent(NS_IMAGE_ERROR);
|
2003-02-25 01:20:26 +03:00
|
|
|
} else if (mState & IMAGE_CANSENDLOADEVENT) {
|
2001-04-15 06:13:49 +04:00
|
|
|
// Send load event
|
2003-02-25 01:20:26 +03:00
|
|
|
mState &= ~IMAGE_CANSENDLOADEVENT;
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-07-11 09:44:12 +04:00
|
|
|
FireDOMEvent(NS_IMAGE_LOAD);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageFrame::FrameChanged(imgIContainer *aContainer, nsIPresContext *aPresContext, gfxIImageFrame *aNewFrame, nsRect *aDirtyRect)
|
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
if (!mLoads[0].mRequest)
|
|
|
|
return NS_OK; // if mLoads[0].mRequest is null, this isn't for the first one, so we don't care about it.
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2002-07-01 22:17:35 +04:00
|
|
|
const nsStyleVisibility* vis;
|
|
|
|
::GetStyleData(this, &vis);
|
|
|
|
|
|
|
|
if (!vis->IsVisible())
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
nsCOMPtr<imgIContainer> con;
|
|
|
|
mLoads[0].mRequest->GetImage(getter_AddRefs(con));
|
|
|
|
if (aContainer == con.get()) {
|
|
|
|
nsRect r(*aDirtyRect);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
r.x = NSIntPixelsToTwips(r.x, p2t);
|
|
|
|
r.y = NSIntPixelsToTwips(r.y, p2t);
|
|
|
|
r.width = NSIntPixelsToTwips(r.width, p2t);
|
|
|
|
r.height = NSIntPixelsToTwips(r.height, p2t);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mTransform.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
2001-11-07 08:02:42 +03:00
|
|
|
if (!r.IsEmpty()) {
|
2002-11-06 23:44:51 +03:00
|
|
|
r.x += mBorderPadding.left;
|
|
|
|
r.y += mBorderPadding.top;
|
2001-11-07 08:02:42 +03:00
|
|
|
Invalidate(aPresContext, r, PR_FALSE);
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-13 14:32:43 +03:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
#define MINMAX(_value,_min,_max) \
|
|
|
|
((_value) < (_min) \
|
|
|
|
? (_min) \
|
|
|
|
: ((_value) > (_max) \
|
|
|
|
? (_max) \
|
|
|
|
: (_value)))
|
|
|
|
|
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
|
|
|
{
|
2001-12-11 06:21:13 +03:00
|
|
|
// if mLoads[0].mIntrinsicSize.width and height are 0, then we should
|
|
|
|
// check to see if the size is already known by the image container.
|
|
|
|
if (mLoads[0].mIntrinsicSize.width == 0 &&
|
|
|
|
mLoads[0].mIntrinsicSize.height == 0) {
|
2002-03-26 23:14:05 +03:00
|
|
|
PRBool needMinIconSizing = PR_FALSE;
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
2001-10-06 12:19:44 +04:00
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
nsCOMPtr<imgIContainer> con;
|
|
|
|
mLoads[0].mRequest->GetImage(getter_AddRefs(con));
|
|
|
|
if (con) {
|
2002-02-17 18:31:24 +03:00
|
|
|
nscoord width, height;
|
|
|
|
|
|
|
|
con->GetWidth(&width);
|
|
|
|
con->GetHeight(&height);
|
|
|
|
mLoads[0].mIntrinsicSize.width = NSIntPixelsToTwips(width, p2t);
|
|
|
|
mLoads[0].mIntrinsicSize.height = NSIntPixelsToTwips(height, p2t);
|
2002-03-26 23:14:05 +03:00
|
|
|
} else {
|
|
|
|
// no image container, so we may need to synthesize a minimum size for the image icons
|
|
|
|
needMinIconSizing = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// no request, so we may need to synthesize a minimum size for the image icons
|
|
|
|
needMinIconSizing = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needMinIconSizing) {
|
|
|
|
// XXX: we need this in composer, but it is also good for general quirks mode to always
|
|
|
|
// XXX: have room for the icon
|
|
|
|
// check for quirks mode
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
|
|
|
if (mode == eCompatibility_NavQuirks) {
|
|
|
|
// image request is null or image size not known, probably an invalid image specified
|
|
|
|
// - make the image big enough for the icon (it may not be used if inline alt expansion is used instead)
|
|
|
|
mLoads[0].mIntrinsicSize.width = NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t);
|
|
|
|
mLoads[0].mIntrinsicSize.height = NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t);
|
2001-10-06 12:19:44 +04:00
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mIntrinsicSize = mLoads[0].mIntrinsicSize;
|
|
|
|
|
2001-04-17 13:03:20 +04:00
|
|
|
float t2p, sp2t;
|
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&sp2t);
|
|
|
|
|
|
|
|
// convert from normal twips to scaled twips (printing...)
|
2001-12-11 06:21:13 +03:00
|
|
|
float t2st = t2p * sp2t; // twips to scaled twips
|
|
|
|
nscoord intrinsicWidth =
|
|
|
|
NSToCoordRound(float(mIntrinsicSize.width) * t2st);
|
|
|
|
nscoord intrinsicHeight =
|
|
|
|
NSToCoordRound(float(mIntrinsicSize.height) * t2st);
|
|
|
|
|
|
|
|
// Determine whether the image has fixed content width
|
|
|
|
nscoord widthConstraint = aReflowState.mComputedWidth;
|
|
|
|
nscoord minWidth = aReflowState.mComputedMinWidth;
|
|
|
|
nscoord maxWidth = aReflowState.mComputedMaxWidth;
|
|
|
|
|
|
|
|
// Determine whether the image has fixed content height
|
|
|
|
nscoord heightConstraint = aReflowState.mComputedHeight;
|
|
|
|
nscoord minHeight = aReflowState.mComputedMinHeight;
|
|
|
|
nscoord maxHeight = aReflowState.mComputedMaxHeight;
|
|
|
|
|
|
|
|
PRBool isAutoWidth = widthConstraint == NS_INTRINSICSIZE;
|
|
|
|
if (isAutoWidth)
|
|
|
|
widthConstraint = intrinsicWidth;
|
|
|
|
PRBool isAutoHeight = heightConstraint == NS_UNCONSTRAINEDSIZE;
|
|
|
|
if (isAutoHeight)
|
|
|
|
heightConstraint = intrinsicHeight;
|
|
|
|
|
|
|
|
nscoord newWidth = MINMAX(widthConstraint, minWidth, maxWidth);
|
|
|
|
nscoord newHeight = MINMAX(heightConstraint, minHeight, maxHeight);
|
|
|
|
|
|
|
|
if (isAutoWidth && newWidth != intrinsicWidth)
|
|
|
|
isAutoWidth = PR_FALSE;
|
|
|
|
if (isAutoHeight && newHeight != intrinsicHeight)
|
|
|
|
isAutoHeight = PR_FALSE;
|
|
|
|
|
|
|
|
if (isAutoWidth) {
|
|
|
|
if (!isAutoHeight && intrinsicHeight != 0) {
|
|
|
|
newWidth = (intrinsicWidth * newHeight) / intrinsicHeight;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
} else {
|
2001-12-11 06:21:13 +03:00
|
|
|
if (isAutoHeight && intrinsicWidth != 0) {
|
|
|
|
newHeight = (intrinsicHeight * newWidth) / intrinsicWidth;
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mComputedSize.width = newWidth;
|
|
|
|
mComputedSize.height = newHeight;
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
nsTransform2D *transform = &mLoads[0].mTransform;
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
if (mComputedSize == mIntrinsicSize) {
|
2001-10-06 09:08:16 +04:00
|
|
|
transform->SetToIdentity();
|
2001-04-15 06:13:49 +04:00
|
|
|
} else {
|
2001-04-15 09:15:48 +04:00
|
|
|
if (mIntrinsicSize.width != 0 && mIntrinsicSize.height != 0) {
|
2001-10-06 09:08:16 +04:00
|
|
|
transform->SetToScale(float(mComputedSize.width) / float(mIntrinsicSize.width),
|
2001-04-15 09:15:48 +04:00
|
|
|
float(mComputedSize.height) / float(mIntrinsicSize.height));
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
aDesiredSize.width = mComputedSize.width;
|
|
|
|
aDesiredSize.height = mComputedSize.height;
|
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);
|
2001-11-01 18:31:13 +03:00
|
|
|
aInnerArea.height = (!mPrevInFlow && !mNextInFlow)
|
|
|
|
? mRect.height - mBorderPadding.top - mBorderPadding.bottom : mComputedSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
return mParent->ReflowDirtyChild(shell, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the offset into the content area of the image where aImg starts if it is a continuation.
|
|
|
|
nscoord
|
|
|
|
nsImageFrame::GetContinuationOffset(nscoord* aWidth) const
|
|
|
|
{
|
|
|
|
nscoord offset = 0;
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
for (nsIFrame* prevInFlow = mPrevInFlow ; prevInFlow; prevInFlow->GetPrevInFlow(&prevInFlow)) {
|
|
|
|
nsRect rect;
|
|
|
|
prevInFlow->GetRect(rect);
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = rect.width;
|
|
|
|
}
|
|
|
|
offset += rect.height;
|
|
|
|
}
|
|
|
|
offset -= mBorderPadding.top;
|
|
|
|
offset = PR_MAX(0, offset);
|
|
|
|
}
|
|
|
|
return offset;
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
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");
|
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2001-03-06 03:47:46 +03:00
|
|
|
// see if we have a frozen size (i.e. a fixed width and height)
|
2003-02-25 01:20:26 +03:00
|
|
|
if (HaveFixedSize(aReflowState)) {
|
|
|
|
mState |= IMAGE_SIZECONSTRAINED;
|
|
|
|
} else {
|
|
|
|
mState &= ~IMAGE_SIZECONSTRAINED;
|
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
if (aReflowState.reason == eReflowReason_Initial)
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_GOTINITIALREFLOW;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
// get the desired size of the complete image
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
2001-11-01 18:31:13 +03:00
|
|
|
|
|
|
|
// add borders and padding
|
|
|
|
mBorderPadding = aReflowState.mComputedBorderPadding;
|
|
|
|
aMetrics.width += mBorderPadding.left + mBorderPadding.right;
|
|
|
|
aMetrics.height += mBorderPadding.top + mBorderPadding.bottom;
|
|
|
|
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
nscoord y = GetContinuationOffset(&aMetrics.width);
|
|
|
|
aMetrics.height -= y + mBorderPadding.top;
|
|
|
|
aMetrics.height = PR_MAX(0, aMetrics.height);
|
|
|
|
}
|
|
|
|
|
2002-01-11 22:32:55 +03:00
|
|
|
|
|
|
|
// we have to split images if we are:
|
|
|
|
// in Paginated mode, we need to have a constrained height, and have a height larger than our available height
|
|
|
|
PRBool isPaginated;
|
|
|
|
aPresContext->IsPaginated(&isPaginated);
|
2002-08-29 05:44:15 +04:00
|
|
|
PRUint32 loadStatus = imgIRequest::STATUS_NONE;
|
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
mLoads[0].mRequest->GetImageStatus(&loadStatus);
|
|
|
|
}
|
|
|
|
if (isPaginated &&
|
2003-02-25 01:20:26 +03:00
|
|
|
((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || (mState & IMAGE_SIZECONSTRAINED)) &&
|
2002-01-11 22:32:55 +03:00
|
|
|
(NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight) &&
|
2001-11-01 18:31:13 +03:00
|
|
|
(aMetrics.height > aReflowState.availableHeight)) {
|
|
|
|
nsCOMPtr<nsIAtom> fType;
|
|
|
|
GetFrameType(getter_AddRefs(fType));
|
|
|
|
// split an image frame but not an image control frame
|
|
|
|
if (nsLayoutAtoms::imageFrame == fType.get()) {
|
2002-02-25 17:42:12 +03:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
// our desired height was greater than 0, so to avoid infinite splitting, use 1 pixel as the min
|
|
|
|
aMetrics.height = PR_MAX(NSToCoordRound(p2t), aReflowState.availableHeight);
|
2001-11-01 18:31:13 +03:00
|
|
|
aStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aMetrics.mComputeMEW) {
|
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()) {
|
2003-01-09 17:26:32 +03:00
|
|
|
aMetrics.mMaxElementWidth = 0;
|
2000-01-30 21:28:38 +03:00
|
|
|
} else {
|
2003-01-09 17:26:32 +03:00
|
|
|
aMetrics.mMaxElementWidth = aMetrics.width;
|
2000-01-30 21:28:38 +03:00
|
|
|
}
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
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
|
|
|
|
|
|
|
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));
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
1998-11-20 20:21:02 +03:00
|
|
|
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);
|
|
|
|
// Set font and color
|
|
|
|
aRenderingContext.SetColor(color->mColor);
|
2002-05-25 00:11:14 +04:00
|
|
|
SetFontFromStyle(&aRenderingContext, mStyleContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2001-10-31 01:58:00 +03:00
|
|
|
nscoord maxAscent, maxDescent, height;
|
|
|
|
fm->GetMaxAscent(maxAscent);
|
1998-09-09 02:34:40 +04:00
|
|
|
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...
|
2001-06-30 15:02:25 +04:00
|
|
|
const PRUnichar* str = aAltText.get();
|
1998-09-09 02:34:40 +04:00
|
|
|
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
|
2001-10-31 01:58:00 +03:00
|
|
|
aRenderingContext.DrawString(str, maxFit, aRect.x, y + maxAscent);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Move to the next line
|
|
|
|
str += maxFit;
|
|
|
|
strLen -= maxFit;
|
|
|
|
y += height;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(fm);
|
|
|
|
}
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
struct nsRecessedBorder : public nsStyleBorder {
|
1998-09-09 02:34:40 +04:00
|
|
|
nsRecessedBorder(nscoord aBorderWidth)
|
2001-02-07 12:57:26 +03:00
|
|
|
: nsStyleBorder()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
mHasCachedBorder = PR_FALSE;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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);
|
2001-11-07 08:02:42 +03:00
|
|
|
borderEdgeWidth = NSIntPixelsToTwips(ALT_BORDER_WIDTH, p2t);
|
1999-09-17 01:37:37 +04:00
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// if inner area is empty, then make it big enough for at least the icon
|
|
|
|
if (inner.IsEmpty()){
|
|
|
|
inner.SizeBy(2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)),
|
|
|
|
2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)));
|
|
|
|
}
|
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// 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
|
2001-11-07 08:02:42 +03:00
|
|
|
inner.Deflate(NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t),
|
|
|
|
NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t));
|
1998-09-22 07:34:44 +04:00
|
|
|
if (inner.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-19 01:17:12 +03:00
|
|
|
// check if the size of the (deflated) rect is big enough to show the icon
|
|
|
|
// - if not, then just bail, leaving the border rect by itself
|
|
|
|
// NOTE: setting the clip (below) should be enough, but there is a bug in the Linux
|
|
|
|
// rendering context that images are not clipped when a clip rect is set (bugzilla bug 78497)
|
|
|
|
// and also this will be slightly more efficient since we will not try to render any icons
|
|
|
|
// or ALT text into the rect.
|
|
|
|
if (inner.width < NSIntPixelsToTwips(ICON_SIZE, p2t) ||
|
|
|
|
inner.height < NSIntPixelsToTwips(ICON_SIZE, p2t)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-09-22 07:34:44 +04:00
|
|
|
// 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
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
PRBool dispIcon = mIconLoad ? mIconLoad->mPrefShowPlaceholders : PR_TRUE;
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Check if we should display image placeholders
|
|
|
|
if (dispIcon) {
|
|
|
|
PRInt32 size = NSIntPixelsToTwips(ICON_SIZE, p2t);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
PRBool iconUsed = PR_FALSE;
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// see if the icon images are present...
|
|
|
|
if (mIconLoad && mIconLoad->mIconsLoaded) {
|
|
|
|
// pick the correct image
|
|
|
|
NS_ASSERTION( aIconId == NS_ICON_LOADING_IMAGE ||
|
|
|
|
aIconId == NS_ICON_BROKEN_IMAGE, "Invalid Icon ID in DisplayAltFeedback");
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
if (mIconLoad->mIconLoads[aIconId].mRequest) {
|
|
|
|
mIconLoad->mIconLoads[aIconId].mRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
}
|
|
|
|
if (imgCon) {
|
|
|
|
// draw it
|
|
|
|
nsPoint p(inner.x, inner.y);
|
|
|
|
nsRect r(0,0,size,size);
|
|
|
|
aRenderingContext.DrawImage(imgCon, &r, &p);
|
|
|
|
iconUsed = PR_TRUE;
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// if we could not draw the image, then just draw some grafitti
|
|
|
|
if (!iconUsed) {
|
|
|
|
nscolor oldColor;
|
|
|
|
aRenderingContext.DrawRect(0,0,size,size);
|
|
|
|
aRenderingContext.GetColor(oldColor);
|
|
|
|
aRenderingContext.SetColor( aIconId == NS_ICON_BROKEN_IMAGE ? NS_RGB(0xFF,0,0) : NS_RGB(0,0xFF,0));
|
|
|
|
aRenderingContext.FillEllipse(NS_STATIC_CAST(int,size/2),NS_STATIC_CAST(int,size/2),
|
|
|
|
NS_STATIC_CAST(int,(size/2)-(2*p2t)),NS_STATIC_CAST(int,(size/2)-(2*p2t)));
|
|
|
|
aRenderingContext.SetColor(oldColor);
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Reduce the inner rect by the width of the icon, and leave an
|
|
|
|
// additional ICON_PADDING pixels for padding
|
|
|
|
PRInt32 iconWidth = NSIntPixelsToTwips(ICON_SIZE + ICON_PADDING, p2t);
|
|
|
|
inner.x += iconWidth;
|
|
|
|
inner.width -= iconWidth;
|
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
2001-11-07 08:02:42 +03:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
nsAutoString altText;
|
|
|
|
|
|
|
|
GetContent(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
content->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag) {
|
|
|
|
nsCSSFrameConstructor::GetAlternateTextFor(content, tag, altText);
|
|
|
|
DisplayAltText(aPresContext, aRenderingContext, altText, inner);
|
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2001-09-19 16:35:19 +04:00
|
|
|
nsImageFrame::Paint(nsIPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 16:35:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2001-01-27 17:09:34 +03:00
|
|
|
PRBool isVisible;
|
|
|
|
if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) &&
|
|
|
|
isVisible && mRect.width && mRect.height) {
|
2001-04-25 23:52:49 +04:00
|
|
|
// If painting is suppressed, we need to stop image painting. We
|
|
|
|
// have to cover <img> here because of input image controls.
|
|
|
|
PRBool paintingSuppressed = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
shell->IsPaintingSuppressed(&paintingSuppressed);
|
|
|
|
if (paintingSuppressed)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
|
2002-04-09 05:16:48 +04:00
|
|
|
// First paint background and borders, which should be in the
|
|
|
|
// FOREGROUND or BACKGROUND paint layer if the element is
|
|
|
|
// inline-level or block-level, respectively. (See CSS2 9.5, which
|
|
|
|
// is the rationale for paint layers.)
|
|
|
|
const nsStyleDisplay *display;
|
2003-02-22 03:32:13 +03:00
|
|
|
::GetStyleData(mStyleContext, &display);
|
2002-04-09 05:16:48 +04:00
|
|
|
nsFramePaintLayer backgroundLayer = display->IsBlockLevel()
|
|
|
|
? NS_FRAME_PAINT_LAYER_BACKGROUND
|
|
|
|
: NS_FRAME_PAINT_LAYER_FOREGROUND;
|
|
|
|
if (aWhichLayer == backgroundLayer) {
|
2002-12-24 01:05:47 +03:00
|
|
|
PaintSelf(aPresContext, aRenderingContext, aDirtyRect);
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
PRUint32 loadStatus = imgIRequest::STATUS_ERROR;
|
|
|
|
|
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
mLoads[0].mRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
mLoads[0].mRequest->GetImageStatus(&loadStatus);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
2001-04-17 13:03:20 +04:00
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
if (loadStatus & imgIRequest::STATUS_ERROR || !imgCon) {
|
1998-09-22 08:01:16 +04:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
2001-11-30 23:47:06 +03:00
|
|
|
// indicating the status (unless image is blocked, in which case we show nothing)
|
2002-03-26 23:14:05 +03:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
#ifndef SUPPRESS_LOADING_ICON
|
2001-11-30 23:47:06 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer &&
|
2003-02-25 01:20:26 +03:00
|
|
|
(!(mState & IMAGE_BLOCKED) || mIconLoad->mPrefAllImagesBlocked)) {
|
2001-11-07 08:02:42 +03:00
|
|
|
#else
|
2000-04-01 04:13:51 +04:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer &&
|
2003-02-25 01:20:26 +03:00
|
|
|
(mState & IMAGE_INITIALLOADCOMPLETED)) {
|
2001-11-07 08:02:42 +03:00
|
|
|
#endif
|
|
|
|
DisplayAltFeedback(aPresContext, aRenderingContext,
|
2001-03-22 04:38:35 +03:00
|
|
|
(loadStatus & imgIRequest::STATUS_ERROR)
|
1998-12-18 18:54:23 +03:00
|
|
|
? 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 {
|
2002-03-12 18:35:52 +03:00
|
|
|
PRBool paintOutline = PR_FALSE;
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_INITIALLOADCOMPLETED;
|
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);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
if (loadStatus & imgIRequest::STATUS_ERROR) {
|
|
|
|
if (imgCon) {
|
|
|
|
inner.SizeTo(mComputedSize);
|
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
2000-04-19 18:00:11 +04:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
if (imgCon) {
|
2001-11-01 18:31:13 +03:00
|
|
|
nscoord offsetY = 0;
|
|
|
|
nsSize size(inner.width, inner.height);
|
|
|
|
// if the image is split account for y-offset, border, padding
|
|
|
|
if (mPrevInFlow || mNextInFlow) {
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
offsetY = GetContinuationOffset();
|
|
|
|
}
|
|
|
|
size.height = mRect.height;
|
|
|
|
if (!mPrevInFlow) {
|
|
|
|
size.height -= mBorderPadding.top;
|
|
|
|
}
|
|
|
|
if (!mNextInFlow) {
|
|
|
|
size.height -= mBorderPadding.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
if (mLoads[0].mIntrinsicSize == mComputedSize) {
|
2001-03-22 04:38:35 +03:00
|
|
|
inner.IntersectRect(inner, aDirtyRect);
|
2001-12-05 11:35:05 +03:00
|
|
|
nsPoint p(inner.x, inner.y);
|
2001-03-22 04:38:35 +03:00
|
|
|
nsRect r(inner.x, inner.y, inner.width, inner.height);
|
|
|
|
r.x -= mBorderPadding.left;
|
|
|
|
r.y -= mBorderPadding.top;
|
2001-11-01 18:31:13 +03:00
|
|
|
if (mPrevInFlow) {
|
|
|
|
r.y = offsetY;
|
2001-12-05 11:35:05 +03:00
|
|
|
p.y = 0;
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
aRenderingContext.DrawImage(imgCon, &r, &p);
|
|
|
|
} else {
|
|
|
|
nsTransform2D trans;
|
2001-10-06 09:08:16 +04:00
|
|
|
trans.SetToScale((float(mLoads[0].mIntrinsicSize.width) / float(inner.width)),
|
|
|
|
(float(mLoads[0].mIntrinsicSize.height) / float(inner.height)));
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
nsRect r(0, offsetY, size.width, size.height);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
trans.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
|
|
|
|
|
|
|
nsRect d(inner.x, inner.y, mComputedSize.width, mComputedSize.height);
|
2001-11-01 18:31:13 +03:00
|
|
|
// if the image is split account for y-offset, border, padding
|
|
|
|
if (mPrevInFlow || mNextInFlow) {
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
d.y -= mBorderPadding.top;
|
|
|
|
}
|
|
|
|
d.height = size.height;
|
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
aRenderingContext.DrawScaledImage(imgCon, &r, &d);
|
|
|
|
}
|
2002-03-12 18:35:52 +03:00
|
|
|
paintOutline = PR_TRUE;
|
2001-03-22 04:38:35 +03: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);
|
2002-03-12 18:35:52 +03:00
|
|
|
paintOutline = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// paint the outline in the overlay layer (or if there is an image map) until the
|
|
|
|
// general problem of painting it outside the border box is solved.
|
|
|
|
if (paintOutline) {
|
|
|
|
const nsStyleBorder* myBorder = (const nsStyleBorder*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Border);
|
|
|
|
const nsStyleOutline* myOutline = (const nsStyleOutline*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Outline);
|
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, rect, *myBorder,
|
|
|
|
*myOutline, mStyleContext, 0);
|
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-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
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2001-12-18 04:29:49 +03:00
|
|
|
PRInt16 displaySelection = 0;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
result = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = shell->GetSelectionFlags(&displaySelection);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES))
|
|
|
|
return NS_OK;//no need to check the blue border, we cannot be drawn selected
|
1999-05-17 04:21:18 +04:00
|
|
|
|
2002-04-11 05:11:23 +04:00
|
|
|
return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, nsISelectionDisplay::DISPLAY_IMAGES);
|
2002-08-17 05:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetImageMap(nsIPresContext *aPresContext, nsIImageMap **aImageMap)
|
|
|
|
{
|
|
|
|
nsImageMap *map = GetImageMap(aPresContext);
|
|
|
|
return map->QueryInterface(NS_GET_IID(nsIImageMap), (void**)aImageMap);
|
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
|
|
|
{
|
2001-04-18 04:14:34 +04:00
|
|
|
if (!mImageMap) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (!doc) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-04-18 04:14:34 +04:00
|
|
|
nsAutoString usemap;
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap);
|
1999-08-20 02:22:02 +04:00
|
|
|
|
2001-04-18 04:14:34 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> map;
|
|
|
|
if (NS_SUCCEEDED(nsImageMapUtils::FindImageMap(doc,usemap,getter_AddRefs(map))) && map) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-04-18 04:14:34 +04:00
|
|
|
mImageMap = new nsImageMap();
|
|
|
|
if (mImageMap) {
|
|
|
|
NS_ADDREF(mImageMap);
|
|
|
|
mImageMap->Init(presShell, this, 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,
|
2002-11-20 03:44:26 +03:00
|
|
|
nsIURI* aURI,
|
1998-11-20 20:21:02 +03:00
|
|
|
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
|
2002-11-20 03:44:26 +03:00
|
|
|
nsCOMPtr<nsILinkHandler> handler;
|
|
|
|
aPresContext->GetLinkHandler(getter_AddRefs(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;
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(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)
|
2001-06-20 07:27:48 +04:00
|
|
|
doc->GetDocumentURL(getter_AddRefs(baseURI));
|
2000-08-09 00:35:12 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-11-20 03:44:26 +03:00
|
|
|
proceed = securityManager->CheckLoadURI(baseURI, aURI, 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))
|
2002-11-20 03:44:26 +03:00
|
|
|
handler->OnLinkClick(mContent, eLinkVerb_Replace, aURI, aTargetSpec.get());
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-11-20 03:44:26 +03:00
|
|
|
handler->OnOverLink(mContent, aURI, aTargetSpec.get());
|
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 ==
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::ismap, ismap);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
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
|
2001-04-11 12:12:10 +04:00
|
|
|
nsImageFrame::GetAnchorHREFAndTarget(nsString& aHref, nsString& aTarget)
|
1999-07-08 23:38:08 +04:00
|
|
|
{
|
1999-07-08 23:44:42 +04:00
|
|
|
PRBool status = PR_FALSE;
|
2001-04-11 12:12:10 +04:00
|
|
|
aHref.Truncate();
|
|
|
|
aTarget.Truncate();
|
1999-07-08 23:38:08 +04:00
|
|
|
|
|
|
|
// 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) {
|
2001-04-11 12:12:10 +04:00
|
|
|
anchor->GetHref(aHref);
|
|
|
|
if (aHref.Length() > 0) {
|
1999-07-08 23:44:42 +04:00
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
2001-04-11 12:12:10 +04:00
|
|
|
anchor->GetTarget(aTarget);
|
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
|
|
|
}
|
|
|
|
|
2001-08-30 02:59:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::CanContinueTextRun(PRBool& aContinueTextRun) const
|
|
|
|
{
|
2001-09-08 23:26:34 +04:00
|
|
|
// images really CAN continue text runs, but the textFrame needs to be
|
|
|
|
// educated before we can indicate that it can. For now, we handle the fixing up
|
|
|
|
// of max element widths in nsLineLayout::VerticalAlignFrames, but hopefully
|
|
|
|
// this can be eliminated and the textFrame can be convinced to handle inlines
|
|
|
|
// that take up space in text runs.
|
2001-08-30 02:59:09 +04:00
|
|
|
|
2001-09-08 23:26:34 +04:00
|
|
|
aContinueTextRun = PR_FALSE;
|
2001-08-30 02:59:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 inside = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIContent> area;
|
|
|
|
inside = map->IsInside(p.x, p.y, getter_AddRefs(area),
|
2002-11-29 02:02:31 +03:00
|
|
|
absURL, target, altText);
|
2000-02-11 04:24:59 +03:00
|
|
|
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;
|
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),
|
2002-11-29 02:02:31 +03:00
|
|
|
absURL, target, altText);
|
1999-01-15 04:57:58 +03:00
|
|
|
}
|
2001-05-23 11:00:37 +04:00
|
|
|
|
1999-08-20 02:22:02 +04:00
|
|
|
if (!inside && isServerMap) {
|
2001-05-23 11:00:37 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURL;
|
|
|
|
GetBaseURI(getter_AddRefs(baseURL));
|
1999-08-20 02:22:02 +04:00
|
|
|
|
2001-05-26 09:46:33 +04:00
|
|
|
if (baseURL) {
|
|
|
|
// Server side image maps use the href in a containing anchor
|
|
|
|
// element to provide the basis for the destination url.
|
|
|
|
nsAutoString src;
|
|
|
|
if (GetAnchorHREFAndTarget(src, target)) {
|
2002-11-20 03:44:26 +03:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
mContent->GetNodeInfo(*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ASSERTION(nodeInfo, "Image content without a nodeinfo?");
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nodeInfo->GetDocument(*getter_AddRefs(doc));
|
|
|
|
nsAutoString charset;
|
|
|
|
if (doc) {
|
|
|
|
doc->GetDocumentCharacterSet(charset);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), src,
|
|
|
|
NS_LossyConvertUCS2toASCII(charset).get(),
|
|
|
|
baseURL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-20 02:22:02 +04:00
|
|
|
|
2001-05-26 09:46:33 +04:00
|
|
|
// 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;
|
2002-11-20 03:44:26 +03:00
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
|
|
|
|
if (url) {
|
|
|
|
url->SetQuery(nsPrintfCString("%d,%d", p.x, p.y));
|
|
|
|
} else {
|
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
spec += nsPrintfCString("?%d,%d", p.x, p.y);
|
|
|
|
uri->SetSpec(spec);
|
|
|
|
}
|
|
|
|
|
2001-05-26 09:46:33 +04:00
|
|
|
PRBool clicked = PR_FALSE;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
clicked = PR_TRUE;
|
|
|
|
}
|
2002-11-20 03:44:26 +03:00
|
|
|
TriggerLink(aPresContext, uri, target, clicked);
|
1999-08-20 02:22:02 +04:00
|
|
|
}
|
2001-05-26 09:46:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_WARNING("baseURL is null for imageFrame - ignoring mouse event");
|
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
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
return nsSplittableFrame::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.
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleUserInterface* styleUserInterface;
|
|
|
|
GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)styleUserInterface);
|
|
|
|
aCursor = styleUserInterface->mCursor;
|
1998-11-24 01:21:13 +03:00
|
|
|
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,
|
2001-08-25 06:01:08 +04:00
|
|
|
PRInt32 aModType,
|
1998-11-20 20:21:02 +03:00
|
|
|
PRInt32 aHint)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2001-11-01 18:31:13 +03:00
|
|
|
nsresult rv = nsSplittableFrame::AttributeChanged(aPresContext, aChild,
|
|
|
|
aNameSpaceID, aAttribute, aModType, 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) {
|
2001-05-04 10:29:59 +04:00
|
|
|
nsAutoString newSRC;
|
2001-08-17 12:14:14 +04:00
|
|
|
aChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, newSRC);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
|
2002-03-07 01:45:55 +03:00
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
PRUint32 loadStatus = imgIRequest::STATUS_ERROR;
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mRequest->GetImageStatus(&loadStatus);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2002-03-07 01:45:55 +03:00
|
|
|
if (!(loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
2003-02-25 01:20:26 +03:00
|
|
|
mState &= ~IMAGE_FAILUREREPLACE; // don't cause a CantRenderReplacedElement call
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mRequest->Cancel(NS_ERROR_FAILURE);
|
|
|
|
mLoads[0].mRequest = nsnull;
|
1999-04-14 01:51:20 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_CANSENDLOADEVENT;
|
2002-03-07 01:45:55 +03:00
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
if (mLoads[1].mRequest) {
|
|
|
|
mLoads[1].mRequest->Cancel(NS_ERROR_FAILURE);
|
|
|
|
mLoads[1].mRequest = nsnull;
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
2002-03-07 01:45:55 +03:00
|
|
|
|
2001-10-14 05:17:08 +04:00
|
|
|
nsCOMPtr<imgIRequest> req(do_CreateInstance("@mozilla.org/image/request;1"));
|
|
|
|
if (!mLoads[0].mRequest) {
|
|
|
|
mLoads[0].mRequest = req;
|
|
|
|
} else {
|
|
|
|
mLoads[1].mRequest = req;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadImage(newSRC, aPresContext, req);
|
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);
|
2001-03-06 03:47:46 +03:00
|
|
|
// NOTE: mSizeFixed will be updated in Reflow...
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-31 07:43:48 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::List(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
ListTag(out);
|
|
|
|
#ifdef DEBUG_waterson
|
|
|
|
fprintf(out, " [parent=%p]", mParent);
|
|
|
|
#endif
|
|
|
|
nsIView* view;
|
|
|
|
GetView(aPresContext, &view);
|
|
|
|
if (view) {
|
|
|
|
fprintf(out, " [view=%p]", view);
|
|
|
|
}
|
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width,
|
|
|
|
mRect.height);
|
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
|
|
|
}
|
|
|
|
fprintf(out, " [content=%p]", mContent);
|
|
|
|
|
|
|
|
// output the img src url
|
2002-03-21 01:14:27 +03:00
|
|
|
if (mLoads[0].mRequest) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mLoads[0].mRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
nsCAutoString uristr;
|
|
|
|
uri->GetAsciiSpec(uristr);
|
|
|
|
fprintf(out, " [src=%s]", uristr.get());
|
|
|
|
}
|
2001-10-31 07:43:48 +03:00
|
|
|
fputs("\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-01-04 06:06:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
aSize = mLoads[0].mIntrinsicSize;
|
2000-01-04 06:06:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-09 02:52:05 +04:00
|
|
|
NS_IMETHODIMP
|
2001-05-04 10:29:59 +04:00
|
|
|
nsImageFrame::GetNaturalImageSize(PRUint32 *naturalWidth,
|
2000-09-09 02:52:05 +04:00
|
|
|
PRUint32 *naturalHeight)
|
|
|
|
{
|
2001-03-24 00:52:08 +03:00
|
|
|
*naturalWidth = 0;
|
|
|
|
*naturalHeight = 0;
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
if (mLoads[0].mRequest) {
|
2001-03-24 00:52:08 +03:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mRequest->GetImage(getter_AddRefs(container));
|
2001-03-24 00:52:08 +03:00
|
|
|
if (container) {
|
|
|
|
PRInt32 w, h;
|
|
|
|
container->GetWidth(&w);
|
|
|
|
container->GetHeight(&h);
|
|
|
|
|
|
|
|
*naturalWidth = NS_STATIC_CAST(PRUint32, w);
|
|
|
|
*naturalHeight = NS_STATIC_CAST(PRUint32, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-09 02:52:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-04 01:11:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetImageRequest(imgIRequest **aRequest)
|
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
*aRequest = mLoads[0].mRequest;
|
2001-08-04 01:11:03 +04:00
|
|
|
NS_IF_ADDREF(*aRequest);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-07 02:41:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IsImageComplete(PRBool* aComplete)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aComplete);
|
2001-10-06 09:08:16 +04:00
|
|
|
if (!mLoads[0].mRequest) {
|
2001-04-17 13:03:20 +04:00
|
|
|
*aComplete = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
PRUint32 status;
|
2001-10-06 09:08:16 +04:00
|
|
|
mLoads[0].mRequest->GetImageStatus(&status);
|
2001-03-22 04:38:35 +03:00
|
|
|
*aComplete = ((status & imgIRequest::STATUS_LOAD_COMPLETE) != 0);
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2000-01-07 02:41:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
nsresult
|
2002-03-24 01:26:36 +03:00
|
|
|
nsImageFrame::LoadImage(const nsAString& aSpec, nsIPresContext *aPresContext, imgIRequest *aRequest, PRBool aCheckContentPolicy)
|
2001-10-07 22:02:13 +04:00
|
|
|
{
|
2002-03-16 08:46:26 +03:00
|
|
|
nsresult rv = RealLoadImage(aSpec, aPresContext, aRequest, aCheckContentPolicy);
|
2001-10-07 22:02:13 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
int whichLoad = GetImageLoad(aRequest);
|
|
|
|
if (whichLoad == -1) return NS_ERROR_FAILURE;
|
|
|
|
mLoads[whichLoad].mRequest = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-24 01:26:36 +03:00
|
|
|
nsImageFrame::RealLoadImage(const nsAString& aSpec, nsIPresContext *aPresContext, imgIRequest *aRequest, PRBool aCheckContentPolicy)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
/* set this to TRUE here in case we return early */
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_INITIALLOADCOMPLETED;
|
2001-05-04 10:29:59 +04:00
|
|
|
|
|
|
|
/* don't load the image if aSpec is empty */
|
|
|
|
if (aSpec.IsEmpty()) return NS_ERROR_FAILURE;
|
|
|
|
|
2001-06-06 00:22:52 +04:00
|
|
|
nsCOMPtr<nsIURI> realURI;
|
2001-05-04 10:29:59 +04:00
|
|
|
|
|
|
|
/* don't load the image if some security check fails... */
|
2002-11-06 15:58:05 +03:00
|
|
|
nsCOMPtr<nsIIOService> ioService;
|
|
|
|
aPresContext->GetIOService(getter_AddRefs(ioService));
|
|
|
|
GetRealURI(aSpec, ioService, getter_AddRefs(realURI));
|
2002-03-16 08:46:26 +03:00
|
|
|
if (aCheckContentPolicy)
|
|
|
|
if (!CanLoadImage(realURI)) return NS_ERROR_FAILURE;
|
2001-05-04 10:29:59 +04:00
|
|
|
|
|
|
|
if (!mListener) {
|
|
|
|
nsImageListener *listener = new nsImageListener(this);
|
|
|
|
if (!listener) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(listener);
|
|
|
|
listener->QueryInterface(NS_GET_IID(imgIDecoderObserver), getter_AddRefs(mListener));
|
|
|
|
NS_ASSERTION(mListener, "queryinterface for the listener failed");
|
|
|
|
NS_RELEASE(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgILoader> il(do_GetService("@mozilla.org/image/loader;1", &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
|
|
|
|
|
2001-09-29 21:50:15 +04:00
|
|
|
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
if (aPresContext) {
|
|
|
|
aPresContext->GetImageLoadFlags(loadFlags);
|
|
|
|
}
|
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
/* get the URI, convert internal-gopher-stuff if needed */
|
2001-06-06 00:22:52 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2001-05-04 10:29:59 +04:00
|
|
|
GetURI(aSpec, getter_AddRefs(uri));
|
2002-09-04 02:49:51 +04:00
|
|
|
if (!uri) {
|
|
|
|
if (!realURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-06-06 00:22:52 +04:00
|
|
|
uri = realURI;
|
2002-09-04 02:49:51 +04:00
|
|
|
}
|
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
/* set this back to FALSE before we do the real load */
|
2003-02-25 01:20:26 +03:00
|
|
|
mState &= ~IMAGE_INITIALLOADCOMPLETED;
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2002-03-02 04:26:49 +03:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI));
|
2002-09-17 22:59:41 +04:00
|
|
|
|
|
|
|
// Get the document URI for the referrer...
|
|
|
|
nsCOMPtr<nsIURI> documentURI;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (mContent) {
|
|
|
|
(void) mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
doc->GetDocumentURL(getter_AddRefs(documentURI));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
nsCOMPtr<imgIRequest> tempRequest;
|
2002-09-17 22:59:41 +04:00
|
|
|
return il->LoadImage(uri, baseURI, documentURI, loadGroup, mListener, aPresContext, loadFlags, nsnull, aRequest, getter_AddRefs(tempRequest));
|
2001-05-04 10:29:59 +04:00
|
|
|
}
|
|
|
|
|
2001-06-06 00:22:52 +04:00
|
|
|
#define INTERNAL_GOPHER_LENGTH 16 /* "internal-gopher-" length */
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2002-03-13 01:26:11 +03:00
|
|
|
void
|
2002-03-24 01:26:36 +03:00
|
|
|
nsImageFrame::GetDocumentCharacterSet(nsAString& aCharset) const
|
2002-03-13 01:26:11 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent(do_QueryInterface(mContent, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = htmlContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
(void) doc->GetDocumentCharacterSet(aCharset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
void
|
2002-03-24 01:26:36 +03:00
|
|
|
nsImageFrame::GetURI(const nsAString& aSpec, nsIURI **aURI)
|
2001-04-15 06:13:49 +04:00
|
|
|
{
|
2001-06-06 00:22:52 +04:00
|
|
|
*aURI = nsnull;
|
2001-04-15 06:13:49 +04:00
|
|
|
|
|
|
|
/* Note: navigator 4.* and earlier releases ignored the base tags
|
|
|
|
effect on the builtin images. So we do too. Use aSpec instead
|
|
|
|
of the absolute url...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The prefix for special "internal" images that are well known.
|
|
|
|
Look and see if this is an internal-gopher- url.
|
|
|
|
*/
|
2001-06-06 00:22:52 +04:00
|
|
|
if (NS_LITERAL_STRING("internal-gopher-").Equals(Substring(aSpec, 0, INTERNAL_GOPHER_LENGTH))) {
|
|
|
|
nsAutoString newURI;
|
2001-04-15 06:13:49 +04:00
|
|
|
newURI.Assign(NS_LITERAL_STRING("resource:/res/html/gopher-") +
|
|
|
|
Substring(aSpec, INTERNAL_GOPHER_LENGTH, aSpec.Length() - INTERNAL_GOPHER_LENGTH) +
|
|
|
|
NS_LITERAL_STRING(".gif"));
|
2002-11-06 15:58:05 +03:00
|
|
|
// XXXldb Using GetRealURI seems silly.
|
|
|
|
GetRealURI(newURI, nsnull, aURI);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
2001-05-04 10:29:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-06 15:58:05 +03:00
|
|
|
nsImageFrame::GetRealURI(const nsAString& aSpec, nsIIOService *aIOService,
|
|
|
|
nsIURI **aURI)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
2001-04-15 06:13:49 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
GetBaseURI(getter_AddRefs(baseURI));
|
2002-03-13 01:26:11 +03:00
|
|
|
nsAutoString charset;
|
|
|
|
GetDocumentCharacterSet(charset);
|
|
|
|
NS_NewURI(aURI, aSpec,
|
|
|
|
charset.IsEmpty() ? nsnull : NS_ConvertUCS2toUTF8(charset).get(),
|
2002-11-06 15:58:05 +03:00
|
|
|
baseURI, aIOService);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
void
|
|
|
|
nsImageFrame::GetBaseURI(nsIURI **aURI)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aURI, "null OUT parameter pointer");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent(do_QueryInterface(mContent, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2001-04-17 13:03:20 +04:00
|
|
|
if (mContent) {
|
|
|
|
rv = mContent->GetDocument(*getter_AddRefs(doc));
|
2001-07-04 09:54:09 +04:00
|
|
|
if (doc) {
|
2001-04-17 13:03:20 +04:00
|
|
|
doc->GetBaseURL(*getter_AddRefs(baseURI));
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*aURI = baseURI;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageFrame::GetLoadGroup(nsIPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != aLoadGroup, "null OUT parameter pointer");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
shell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
doc->GetDocumentLoadGroup(aLoadGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
PRBool
|
|
|
|
nsImageFrame::CanLoadImage(nsIURI *aURI)
|
|
|
|
{
|
2001-05-19 04:33:51 +04:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
PRBool shouldLoad = PR_TRUE; // default permit
|
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
// Check with the content-policy things to make sure this load is permitted.
|
2001-04-15 06:13:49 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mContent));
|
|
|
|
|
|
|
|
if (!element) // this would seem bad(tm)
|
2001-05-22 02:40:10 +04:00
|
|
|
return shouldLoad;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
if (mContent) {
|
|
|
|
rv = mContent->GetDocument(*getter_AddRefs(document));
|
2001-07-04 09:54:09 +04:00
|
|
|
if (! document) {
|
2001-05-22 02:40:10 +04:00
|
|
|
NS_ASSERTION(0, "expecting a document");
|
|
|
|
return shouldLoad;
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
|
|
|
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
|
|
|
if (NS_FAILED(rv)) return shouldLoad;
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalScript));
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE,
|
2002-03-16 08:46:26 +03:00
|
|
|
aURI, element, domWin, &shouldLoad);
|
2001-11-30 23:47:06 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && !shouldLoad) {
|
|
|
|
// this image has been blocked, so flag it
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_BLOCKED;
|
2001-11-30 23:47:06 +03:00
|
|
|
return shouldLoad;
|
|
|
|
}
|
2001-05-22 02:40:10 +04:00
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
/* ... additional checks ? */
|
|
|
|
|
|
|
|
return shouldLoad;
|
|
|
|
}
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
nsresult nsImageFrame::LoadIcons(nsIPresContext *aPresContext)
|
|
|
|
{
|
2001-11-21 01:21:14 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(loadingSrc,"resource:/res/loading-image.gif");
|
|
|
|
NS_NAMED_LITERAL_STRING(brokenSrc,"resource:/res/broken-image.gif");
|
2001-11-07 08:02:42 +03:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool doLoad = PR_FALSE; // only load icons once...
|
|
|
|
|
|
|
|
// see if the first instance and we need to create the icon loader
|
|
|
|
if (!mIconLoad) {
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "Allocating IconLoad (%p)\n", this);
|
|
|
|
#endif
|
|
|
|
mIconLoad = new IconLoad(aPresContext);
|
|
|
|
if (!mIconLoad)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
doLoad = PR_TRUE;
|
|
|
|
}
|
|
|
|
// always addref
|
|
|
|
mIconLoad->AddRef();
|
|
|
|
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "IconLoad AddRef'd(%p)\n", this);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// if already loaded, we are done
|
|
|
|
if (mIconLoad->mIconsLoaded) return rv;
|
|
|
|
|
|
|
|
if (doLoad) {
|
|
|
|
// create a loader and load the images
|
|
|
|
mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest = do_CreateInstance("@mozilla.org/image/request;1");
|
|
|
|
if (mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest) {
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "Loading request %p\n", mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest.get() );
|
|
|
|
#endif
|
2002-03-16 08:46:26 +03:00
|
|
|
rv = LoadImage(loadingSrc, aPresContext, mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest, PR_FALSE);
|
2001-11-07 08:02:42 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mIconLoad->mIconLoads[NS_ICON_BROKEN_IMAGE].mRequest = do_CreateInstance("@mozilla.org/image/request;1");
|
|
|
|
if (mIconLoad->mIconLoads[NS_ICON_BROKEN_IMAGE].mRequest) {
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "Loading request %p\n", mIconLoad->mIconLoads[NS_ICON_BROKEN_IMAGE].mRequest.get() );
|
|
|
|
#endif
|
2002-03-16 08:46:26 +03:00
|
|
|
rv = LoadImage(brokenSrc, aPresContext, mIconLoad->mIconLoads[NS_ICON_BROKEN_IMAGE].mRequest, PR_FALSE);
|
2001-11-07 08:02:42 +03:00
|
|
|
// ImageLoader will callback into OnStartContainer, which will handle the mIconsLoaded flag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsImageFrame::HandleIconLoads(imgIRequest* aRequest, PRBool aLoaded)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if( mIconLoad ) {
|
|
|
|
// check which image it is
|
|
|
|
if (aRequest == mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest.get()) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
} else if (aRequest == mIconLoad->mIconLoads[NS_ICON_BROKEN_IMAGE].mRequest.get()) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
mIconLoad->mIconsLoaded = aLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
if (mIconLoad->mIconsLoaded && result) {
|
|
|
|
printf( "Icons Loaded: request for %s\n", aRequest == mIconLoad->mIconLoads[NS_ICON_LOADING_IMAGE].mRequest ?
|
|
|
|
"NS_ICON_LOADING_IMAGE" : "NS_ICON_BROKEN_IMAGE" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "HandleIconLoads returned %s (%p)\n", result ? "TRUE" : "FALSE", this);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
void nsImageFrame::InvalidateIcon(nsIPresContext *aPresContext)
|
|
|
|
{
|
2002-01-19 01:17:12 +03:00
|
|
|
// invalidate the inner area, where the icon lives
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
NS_ASSERTION(aPresContext, "null presContext in InvalidateIcon");
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
nsRect inner;
|
|
|
|
GetInnerArea(aPresContext, inner);
|
|
|
|
|
|
|
|
nsRect rect(inner.x,
|
|
|
|
inner.y,
|
|
|
|
NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING, p2t),
|
|
|
|
NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING, p2t));
|
2002-01-19 01:17:12 +03:00
|
|
|
NS_ASSERTION(!rect.IsEmpty(), "icon rect cannot be empty!");
|
2001-11-07 08:02:42 +03:00
|
|
|
Invalidate(aPresContext, rect, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2002-03-09 08:31:35 +03:00
|
|
|
void nsImageFrame::IconLoad::GetPrefs(nsIPresContext *aPresContext)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresContext, "null presContext is not allowed in GetAltModePref");
|
|
|
|
// NOTE: the presContext could be used to fetch a cached pref if needed, but is not for now
|
|
|
|
|
2002-12-11 17:05:41 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefBranch) {
|
2001-11-07 08:02:42 +03:00
|
|
|
PRBool boolPref;
|
2002-03-09 08:31:35 +03:00
|
|
|
PRInt32 intPref;
|
2002-12-11 17:05:41 +03:00
|
|
|
if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) {
|
2001-11-07 08:02:42 +03:00
|
|
|
mPrefForceInlineAltText = boolPref;
|
|
|
|
} else {
|
|
|
|
mPrefForceInlineAltText = PR_FALSE;
|
|
|
|
}
|
2002-12-11 17:05:41 +03:00
|
|
|
if (NS_SUCCEEDED(prefBranch->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) {
|
2002-03-09 08:31:35 +03:00
|
|
|
mPrefAllImagesBlocked = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
mPrefAllImagesBlocked = PR_FALSE;
|
|
|
|
}
|
2002-12-11 17:05:41 +03:00
|
|
|
if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) {
|
2002-04-10 18:45:05 +04:00
|
|
|
mPrefShowPlaceholders = boolPref;
|
|
|
|
} else {
|
|
|
|
mPrefShowPlaceholders = PR_TRUE;
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(nsImageListener, imgIDecoderObserver, imgIContainerObserver)
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
nsImageListener::nsImageListener(nsImageFrame *aFrame) :
|
|
|
|
mFrame(aFrame)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageListener::~nsImageListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStartDecode(imgIRequest *aRequest, nsISupports *aContext)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStartDecode(aRequest, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStartContainer(imgIRequest *aRequest, nsISupports *aContext, imgIContainer *aImage)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStartContainer(aRequest, pc, aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStartFrame(imgIRequest *aRequest, nsISupports *aContext, gfxIImageFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStartFrame(aRequest, pc, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnDataAvailable(imgIRequest *aRequest, nsISupports *aContext, gfxIImageFrame *aFrame, const nsRect *aRect)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnDataAvailable(aRequest, pc, aFrame, aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStopFrame(imgIRequest *aRequest, nsISupports *aContext, gfxIImageFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStopFrame(aRequest, pc, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStopContainer(imgIRequest *aRequest, nsISupports *aContext, imgIContainer *aImage)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStopContainer(aRequest, pc, aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::OnStopDecode(imgIRequest *aRequest, nsISupports *aContext, nsresult status, const PRUnichar *statusArg)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->OnStopDecode(aRequest, pc, status, statusArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsImageListener::FrameChanged(imgIContainer *aContainer, nsISupports *aContext, gfxIImageFrame *newframe, nsRect * dirtyRect)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc(do_QueryInterface(aContext));
|
|
|
|
|
|
|
|
NS_ASSERTION(pc, "not a pres context!");
|
|
|
|
|
|
|
|
return mFrame->FrameChanged(aContainer, pc, newframe, dirtyRect);
|
|
|
|
}
|
|
|
|
|